質問編集履歴

2

説明を増やしました

2017/07/26 15:28

投稿

Reo23
Reo23

スコア15

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
- 期間を指定し、期間内であればindexで通知をする機能を作りたいです、dbにデータが入りません。
1
+ select_tagで通知の表示開始期間、表示終了期間を指定し、表示期間内であればindexアクションで通知を表示する機能を作りたいです。しかしselect_tagで選択した情報をpostで送信してもdbにデータが入りません。おそらくmodelの記述が間違っていると思われます。
2
2
 
3
- データを入れ方法をご教授いただけると幸いです。
3
+ 動作す記述が思いつかないのでご教授いただけると幸いです。
4
4
 
5
5
 
6
6
 

1

変数名を変えました

2017/07/26 15:27

投稿

Reo23
Reo23

スコア15

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- st_dateとen_dateのデータ型はdatetimeです。
7
+ start_dateとend_dateのデータ型はdatetimeです。
8
8
 
9
9
  ```HTML
10
10
 
@@ -12,13 +12,13 @@
12
12
 
13
13
 
14
14
 
15
- <%= form_for(@dly_caution) do |f| %>
15
+ <%= form_for(@caution) do |f| %>
16
16
 
17
17
  <div>
18
18
 
19
19
  <label class="control-label" for="">表示開始日時</label>
20
20
 
21
- <%= f.datetime_select :st_date, {}, class: 'form-control' %>
21
+ <%= f.datetime_select :start_date, {}, class: 'form-control' %>
22
22
 
23
23
  </div>
24
24
 
@@ -26,7 +26,7 @@
26
26
 
27
27
  <label class="control-label" for="">表示終了日時</label>
28
28
 
29
- <%= f.datetime_select :en_date, {}, class: 'form-control' %>
29
+ <%= f.datetime_select :end_date, {}, class: 'form-control' %>
30
30
 
31
31
  </div>
32
32
 
@@ -60,13 +60,13 @@
60
60
 
61
61
  index
62
62
 
63
- <% if @dly_cautions.present? %>
63
+ <% if @cautions.present? %>
64
64
 
65
- <% @dly_cautions.each do |dly_caution| %>
65
+ <% @cautions.each do |caution| %>
66
66
 
67
- <%= link_to "#{dly_caution.subject}", edit_dly_caution_path %>
67
+ <%= link_to "#{caution.subject}", edit_caution_path %>
68
68
 
69
- <%= link_to "#{dly_caution.body}", edit_dly_caution_path %>
69
+ <%= link_to "#{caution.body}", edit_caution_path %>
70
70
 
71
71
  <% end %>
72
72
 
@@ -74,7 +74,7 @@
74
74
 
75
75
 
76
76
 
77
- <%= link_to "申し送り作成", "/dly_cautions/new" %>
77
+ <%= link_to "通知作成", "/cautions/new" %>
78
78
 
79
79
 
80
80
 
@@ -86,7 +86,7 @@
86
86
 
87
87
  def new
88
88
 
89
- @dly_caution = DlyCaution.new
89
+ @caution = Caution.new
90
90
 
91
91
  end
92
92
 
@@ -94,17 +94,17 @@
94
94
 
95
95
  def create
96
96
 
97
- @dly_caution = DlyCaution.new(st_date: params[:st_date], en_date: params[:en_date],
97
+ @caution = Caution.new(start_date: params[:start_date], end_date: params[:end_date],
98
98
 
99
99
  subject: params[:subject], body: params[:body], cosmo_id: params[:cosmo_id])
100
100
 
101
- @dly_caution.cosmo_id = @current_operator.cosmo_id
101
+ @caution.cosmo_id = @current_operator.cosmo_id
102
102
 
103
- @dly_caution.save
103
+ @caution.save
104
104
 
105
105
  redirect_to("/")
106
106
 
107
- flash[:notice] = "申し送りを作成しました"
107
+ flash[:notice] = "通知を作成しました"
108
108
 
109
109
  end
110
110
 
@@ -112,7 +112,7 @@
112
112
 
113
113
  def index
114
114
 
115
- @dly_cautions = DlyCaution.find_by_time_now
115
+ @cautions = Caution.find_by_time_now
116
116
 
117
117
  end
118
118
 
@@ -132,7 +132,7 @@
132
132
 
133
133
  def self.find_by_time_now
134
134
 
135
- where("en_date - st_date")
135
+ where("end_date - start_date")
136
136
 
137
137
  end
138
138