-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathad_controller.rb
More file actions
68 lines (59 loc) · 1.51 KB
/
Copy pathad_controller.rb
File metadata and controls
68 lines (59 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require 'date'
class AdController < ApplicationController
def index
@ads = Ad.all
end
def edit
@ad = Ad.find(params[:id])
end
def new
@ad = Ad.new
end
def create
@ad = Ad.new(ad_params)
if @ad.save # 広告登録成功時
flash[:notice] = 'Ad registered!'
redirect_to(ad_index_path)
else
render('ad/new')
end
end
def update
@ad = Ad.find(params[:id])
if @ad.update_attributes(ad_params)
flash[:notice] = 'Ad updated!'
redirect_to(ad_index_path)
else
render('ad/edit')
end
end
def destroy
Ad.find(params[:id]).destroy
flash[:notice] = 'Ad deleted!'
redirect_to(ad_index_path)
end
def report #report.htmlに全レポートを出力
@reports = Report.select("
ad_id,
SUM(reports.imp) AS imp,
SUM(reports.click) AS click,
SUM(reports.cv) AS cv,
SUM(reports.price) AS price
").group(:ad_id)
end
def report_period #report.htmlに一定期間のレポートを出力
@reports = Report.select("
ad_id,
SUM(reports.imp) AS imp,
SUM(reports.click) AS click,
SUM(reports.cv) AS cv,
SUM(reports.price) AS price
").where(date: Date.parse(params[:date_min])..Date.parse(params[:date_max])).group(:ad_id)
render('/ad/report')
end
private
def ad_params # Adオブジェクト作成時にフォームから入力したパラメーターを渡す。
params.require(:ad).permit(:price, :text, :image)
end
end