質問編集履歴
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,9 +102,7 @@
|
|
102
102
|
|
103
103
|
:point_content,
|
104
104
|
|
105
|
-
:coupon_content,
|
106
|
-
|
107
|
-
).merge(user_id: params[:user_id])
|
105
|
+
:coupon_content).merge(user_id: params[:user_id])
|
108
106
|
|
109
107
|
end
|
110
108
|
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,268 +8,272 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
### 発生している問題・エラーメッセージ
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
ActiveSupport::MessageVerifier::InvalidSignature
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
### 該当のソースコード
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
cards_controller.rb
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class CardsController < ApplicationController
|
40
|
+
|
41
|
+
def index
|
42
|
+
|
43
|
+
@cards = Card.all
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def new
|
50
|
+
|
51
|
+
@card_lists = CardList.all
|
52
|
+
|
53
|
+
@point_lists = PointList.all
|
54
|
+
|
55
|
+
@coupon_lists = CouponList.all
|
56
|
+
|
57
|
+
@card = Card.new
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
def create
|
64
|
+
|
65
|
+
@card = Card.new(card_params)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if @card.save
|
70
|
+
|
71
|
+
redirect_to user_cards_path(@card), notice: "カードを追加しました"
|
72
|
+
|
73
|
+
else
|
74
|
+
|
75
|
+
render "new"
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def card_params
|
86
|
+
|
87
|
+
params.require(:card).permit(
|
88
|
+
|
89
|
+
:name,
|
90
|
+
|
91
|
+
:address,
|
92
|
+
|
93
|
+
:opening_hours,
|
94
|
+
|
95
|
+
:closing_hours,
|
96
|
+
|
97
|
+
:phone_num,
|
98
|
+
|
99
|
+
:url,
|
100
|
+
|
101
|
+
:image,
|
102
|
+
|
103
|
+
:point_content,
|
104
|
+
|
105
|
+
:coupon_content,
|
106
|
+
|
107
|
+
).merge(user_id: params[:user_id])
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
createアクションの@card = Card.new(card_params)でエラーが起きています
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
cards/new.html.haml
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
=render "layouts/header"
|
124
|
+
|
125
|
+
.search
|
126
|
+
|
127
|
+
.new-contents.row
|
128
|
+
|
129
|
+
- @card_lists.each do |card_list|
|
130
|
+
|
131
|
+
.content-card.col-lg-5
|
132
|
+
|
133
|
+
=image_tag card_list.image, class:"content-card__image"
|
134
|
+
|
135
|
+
%ul.content-card__info
|
136
|
+
|
137
|
+
%li.content-card__info__name
|
138
|
+
|
139
|
+
=card_list.name
|
140
|
+
|
141
|
+
- @point_lists.each do |point_list|
|
142
|
+
|
143
|
+
%li.content-card__info__point
|
144
|
+
|
145
|
+
=point_list.content
|
146
|
+
|
147
|
+
- @coupon_lists.each do |coupon_list|
|
148
|
+
|
149
|
+
%li.content-card__info__coupon
|
150
|
+
|
151
|
+
=coupon_list.content
|
152
|
+
|
153
|
+
=form_with model:@card, url: user_cards_url, method: :post, local: true do |f|
|
154
|
+
|
155
|
+
- @card_lists.each do |card_list|
|
156
|
+
|
157
|
+
=f.hidden_field :name, value: card_list.name
|
158
|
+
|
159
|
+
=f.hidden_field :address, value: card_list.address
|
160
|
+
|
161
|
+
=f.hidden_field :opening_hours, value: card_list.opening_hours
|
162
|
+
|
163
|
+
=f.hidden_field :closing_hours, value: card_list.closing_hours
|
164
|
+
|
165
|
+
=f.hidden_field :phone_num, value: card_list.phone_num
|
166
|
+
|
167
|
+
=f.hidden_field :url, value: card_list.url
|
168
|
+
|
169
|
+
=f.hidden_field :image, value: card_list.image
|
170
|
+
|
171
|
+
- @point_lists.each do |point_list|
|
172
|
+
|
173
|
+
=f.hidden_field :point_content, value: point_list.content
|
174
|
+
|
175
|
+
- @coupon_lists.each do |coupon_list|
|
176
|
+
|
177
|
+
=f.hidden_field :coupon_content, value: coupon_list.content
|
178
|
+
|
179
|
+
= f.submit "追加", class: 'btn btn-success'
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
hidden_fieldを使ってformを作成しました。
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
cardsのマイグレーションファイル(1)
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
class CreateCards < ActiveRecord::Migration[5.2]
|
192
|
+
|
193
|
+
def change
|
194
|
+
|
195
|
+
create_table :cards do |t|
|
196
|
+
|
197
|
+
t.references :user, foreign_key: true
|
198
|
+
|
199
|
+
t.string :name, null: false
|
200
|
+
|
201
|
+
t.string :address, null: false
|
202
|
+
|
203
|
+
t.time :opening_hours, null: false
|
204
|
+
|
205
|
+
t.time :closing_hours, null: false
|
206
|
+
|
207
|
+
t.string :phone_num, null: false
|
208
|
+
|
209
|
+
t.text :url
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
t.timestamps
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
```
|
224
|
+
|
225
|
+
cardsのマイグレーションファイル(2)
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
class AddContentToCards < ActiveRecord::Migration[5.2]
|
230
|
+
|
231
|
+
def change
|
232
|
+
|
233
|
+
add_column :cards, :point_content, :string
|
234
|
+
|
235
|
+
add_column :cards, :coupon_content, :string
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
```
|
246
|
+
|
247
|
+
cardを新規作成したときのパラメータです
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
Started POST "/users/1/cards" for ::1 at 2020-03-23 07:22:01 +0900
|
252
|
+
|
253
|
+
Processing by CardsController#create as HTML
|
254
|
+
|
255
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ms9I2+wCDBTiSRLdcKSPNm1RRdqq632cKvcW0bZ9lGRfrcer0KAgWhvrZ6UfI3FLLYohIPq7z9EV5Ez5csi2qg==", "card"=>{"name"=>"久兵衛", "address"=>"東京", "opening_hours"=>"2000-01-01 11:00:00 UTC", "closing_hours"=>"2000-01-01 22:00:00 UTC", "phone_num"=>"9999999999", "url"=>"http://www.kyubey.jp/", "image"=>"#<ActiveStorage::Attached::One:0x00007f94b8e92498>", "point_content"=>"いか二貫", "coupon_content"=>"200円引き"}, "commit"=>"追加", "user_id"=>"1"}
|
256
|
+
|
257
|
+
Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.0ms)
|
258
|
+
|
259
|
+
```
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
### 試したこと
|
264
|
+
|
265
|
+
MessageVerifierについて調べました。
|
266
|
+
|
267
|
+
Cookieで改ざんのチェックに利用していて、検証をおこなっているとわかりました。
|
268
|
+
|
269
|
+
なのでauthenticate_tokenの検証でエラーになっていると思い、
|
270
|
+
|
271
|
+
下記の記事を参考に
|
272
|
+
|
273
|
+
ブラウザを閉じて、やり直しましたがうまくいきませんでした。
|
274
|
+
|
275
|
+
https://masamitsu-murase.blogspot.com/2014/06/rails-csrf.html
|
276
|
+
|
277
|
+
|
278
|
+
|
11
279
|
ご教授のほどよろしくお願いいたします
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
### 発生している問題・エラーメッセージ
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
ActiveSupport::MessageVerifier::InvalidSignature
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
### 該当のソースコード
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
cards_controller.rb
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
class CardsController < ApplicationController
|
40
|
-
|
41
|
-
def index
|
42
|
-
|
43
|
-
@cards = Card.all
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def new
|
50
|
-
|
51
|
-
@card_lists = CardList.all
|
52
|
-
|
53
|
-
@point_lists = PointList.all
|
54
|
-
|
55
|
-
@coupon_lists = CouponList.all
|
56
|
-
|
57
|
-
@card = Card.new
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def create
|
64
|
-
|
65
|
-
@card = Card.new(card_params)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if @card.save
|
70
|
-
|
71
|
-
redirect_to user_cards_path(@card), notice: "カードを追加しました"
|
72
|
-
|
73
|
-
else
|
74
|
-
|
75
|
-
render "new"
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def card_params
|
86
|
-
|
87
|
-
params.require(:card).permit(
|
88
|
-
|
89
|
-
:name,
|
90
|
-
|
91
|
-
:address,
|
92
|
-
|
93
|
-
:opening_hours,
|
94
|
-
|
95
|
-
:closing_hours,
|
96
|
-
|
97
|
-
:phone_num,
|
98
|
-
|
99
|
-
:url,
|
100
|
-
|
101
|
-
:image,
|
102
|
-
|
103
|
-
:point_content,
|
104
|
-
|
105
|
-
:coupon_content,
|
106
|
-
|
107
|
-
).merge(user_id: params[:user_id])
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
```
|
114
|
-
|
115
|
-
createアクションの@card = Card.new(card_params)でエラーが起きています
|
116
|
-
|
117
|
-
```
|
118
|
-
|
119
|
-
cards/new.html.haml
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
=render "layouts/header"
|
124
|
-
|
125
|
-
.search
|
126
|
-
|
127
|
-
.new-contents.row
|
128
|
-
|
129
|
-
- @card_lists.each do |card_list|
|
130
|
-
|
131
|
-
.content-card.col-lg-5
|
132
|
-
|
133
|
-
=image_tag card_list.image, class:"content-card__image"
|
134
|
-
|
135
|
-
%ul.content-card__info
|
136
|
-
|
137
|
-
%li.content-card__info__name
|
138
|
-
|
139
|
-
=card_list.name
|
140
|
-
|
141
|
-
- @point_lists.each do |point_list|
|
142
|
-
|
143
|
-
%li.content-card__info__point
|
144
|
-
|
145
|
-
=point_list.content
|
146
|
-
|
147
|
-
- @coupon_lists.each do |coupon_list|
|
148
|
-
|
149
|
-
%li.content-card__info__coupon
|
150
|
-
|
151
|
-
=coupon_list.content
|
152
|
-
|
153
|
-
=form_with model:@card, url: user_cards_url, method: :post, local: true do |f|
|
154
|
-
|
155
|
-
- @card_lists.each do |card_list|
|
156
|
-
|
157
|
-
=f.hidden_field :name, value: card_list.name
|
158
|
-
|
159
|
-
=f.hidden_field :address, value: card_list.address
|
160
|
-
|
161
|
-
=f.hidden_field :opening_hours, value: card_list.opening_hours
|
162
|
-
|
163
|
-
=f.hidden_field :closing_hours, value: card_list.closing_hours
|
164
|
-
|
165
|
-
=f.hidden_field :phone_num, value: card_list.phone_num
|
166
|
-
|
167
|
-
=f.hidden_field :url, value: card_list.url
|
168
|
-
|
169
|
-
=f.hidden_field :image, value: card_list.image
|
170
|
-
|
171
|
-
- @point_lists.each do |point_list|
|
172
|
-
|
173
|
-
=f.hidden_field :point_content, value: point_list.content
|
174
|
-
|
175
|
-
- @coupon_lists.each do |coupon_list|
|
176
|
-
|
177
|
-
=f.hidden_field :coupon_content, value: coupon_list.content
|
178
|
-
|
179
|
-
= f.submit "追加", class: 'btn btn-success'
|
180
|
-
|
181
|
-
```
|
182
|
-
|
183
|
-
hidden_fieldを使ってformを作成しました。
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
cardsのマイグレーションファイル(1)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
class CreateCards < ActiveRecord::Migration[5.2]
|
192
|
-
|
193
|
-
def change
|
194
|
-
|
195
|
-
create_table :cards do |t|
|
196
|
-
|
197
|
-
t.references :user, foreign_key: true
|
198
|
-
|
199
|
-
t.string :name, null: false
|
200
|
-
|
201
|
-
t.string :address, null: false
|
202
|
-
|
203
|
-
t.time :opening_hours, null: false
|
204
|
-
|
205
|
-
t.time :closing_hours, null: false
|
206
|
-
|
207
|
-
t.string :phone_num, null: false
|
208
|
-
|
209
|
-
t.text :url
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
t.timestamps
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
end
|
220
|
-
|
221
|
-
```
|
222
|
-
|
223
|
-
```
|
224
|
-
|
225
|
-
cardsのマイグレーションファイル(2)
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
class AddContentToCards < ActiveRecord::Migration[5.2]
|
230
|
-
|
231
|
-
def change
|
232
|
-
|
233
|
-
add_column :cards, :point_content, :string
|
234
|
-
|
235
|
-
add_column :cards, :coupon_content, :string
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
```
|
244
|
-
|
245
|
-
```
|
246
|
-
|
247
|
-
cardを新規作成したときのパラメータです
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
Started POST "/users/1/cards" for ::1 at 2020-03-23 07:22:01 +0900
|
252
|
-
|
253
|
-
Processing by CardsController#create as HTML
|
254
|
-
|
255
|
-
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ms9I2+wCDBTiSRLdcKSPNm1RRdqq632cKvcW0bZ9lGRfrcer0KAgWhvrZ6UfI3FLLYohIPq7z9EV5Ez5csi2qg==", "card"=>{"name"=>"久兵衛", "address"=>"東京", "opening_hours"=>"2000-01-01 11:00:00 UTC", "closing_hours"=>"2000-01-01 22:00:00 UTC", "phone_num"=>"9999999999", "url"=>"http://www.kyubey.jp/", "image"=>"#<ActiveStorage::Attached::One:0x00007f94b8e92498>", "point_content"=>"いか二貫", "coupon_content"=>"200円引き"}, "commit"=>"追加", "user_id"=>"1"}
|
256
|
-
|
257
|
-
Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.0ms)
|
258
|
-
|
259
|
-
```
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
### 試したこと
|
264
|
-
|
265
|
-
MessageVerifierについて調べました。
|
266
|
-
|
267
|
-
Cookieで改ざんのチェックに利用していて、検証をおこなっているとわかりました。
|
268
|
-
|
269
|
-
なのでauthenticate_tokenの検証でエラーになっていると思い、
|
270
|
-
|
271
|
-
https://masamitsu-murase.blogspot.com/2014/06/rails-csrf.html
|
272
|
-
|
273
|
-
こちらの記事を参考に
|
274
|
-
|
275
|
-
ブラウザを閉じて、やり直しましたがうまくいきません。
|