質問編集履歴

5

画像追記

2018/01/26 04:19

投稿

shohike
shohike

スコア8

test CHANGED
File without changes
test CHANGED
@@ -283,3 +283,7 @@
283
283
  ```no implicit conversion of String into Integer```
284
284
 
285
285
  となりました。deviseのRegistrationsController を継承している以下のUsers::RegistrationsControllerのcreateアクションでの挙動がおかしいようです。。
286
+
287
+
288
+
289
+ ![イメージ説明](a274e21ef308a0d8e0718cc6693fca8d.png)

4

追記

2018/01/26 04:19

投稿

shohike
shohike

スコア8

test CHANGED
File without changes
test CHANGED
@@ -219,3 +219,67 @@
219
219
  end
220
220
 
221
221
  ```
222
+
223
+
224
+
225
+ -------追記--------
226
+
227
+ ```
228
+
229
+ <%= f.fields_for :category do |fc| %>
230
+
231
+ <%= fc.collection_check_boxes :category_ids, Category.all, :id, :name %>
232
+
233
+ <% end %>
234
+
235
+ ```
236
+
237
+ にてポストしたところ```Unpermitted parameter: :category```となりましたので、
238
+
239
+ ```
240
+
241
+ <%= f.label :user_categories_attributes ,'カテゴリーの選択' %><br />
242
+
243
+ <%= f.fields_for :user_categories_attributes do |fc| %>
244
+
245
+ <%= fc.collection_check_boxes :category_ids, Category.all, :id, :name ,include_hidden: false%>
246
+
247
+ <% end %>
248
+
249
+ ```
250
+
251
+ へ変更し以下のパラメータで正しいように思われますが、
252
+
253
+ ```
254
+
255
+ Parameters:
256
+
257
+ {"utf8"=>"✓",
258
+
259
+ "authenticity_token"=>"HrQJPZyDbz+j1yr0hxLI98PeiidIwAHx4rOey+U2QOCvDz90lZjhZgwGdczGx6uCtdzvt9px4GpD/LuoNxrI5w==",
260
+
261
+ "user"=>{"name"=>"sasasa",
262
+
263
+ "email"=>"sasasa@aaa.com",
264
+
265
+ "password"=>"[FILTERED]",
266
+
267
+ "password_confirmation"=>"[FILTERED]",
268
+
269
+ "user_categories_attributes"=>{"category_ids"=>["3", "5", "6"]},
270
+
271
+ "birthday(1i)"=>"1984",
272
+
273
+ "birthday(2i)"=>"1", "birthday(3i)"=>"1",
274
+
275
+ "gender"=>"1"},
276
+
277
+ "commit"=>"次へ"}
278
+
279
+ ```
280
+
281
+ #TypeError in Users::RegistrationsController#create
282
+
283
+ ```no implicit conversion of String into Integer```
284
+
285
+ となりました。deviseのRegistrationsController を継承している以下のUsers::RegistrationsControllerのcreateアクションでの挙動がおかしいようです。。

3

タグの追加

2018/01/26 04:16

投稿

shohike
shohike

スコア8

test CHANGED
File without changes
test CHANGED
File without changes

2

collection_check_boxesをf.fields_forで送信に変更

2018/01/25 09:32

投稿

shohike
shohike

スコア8

test CHANGED
File without changes
test CHANGED
@@ -171,3 +171,51 @@
171
171
  お手数ですが、どなたか分かればヒントでもいいのでご教授いただけないでしょうか?
172
172
 
173
173
  宜しくお願い致します。
174
+
175
+
176
+
177
+ ------追記---------------
178
+
179
+
180
+
181
+
182
+
183
+ ### new.html.erb
184
+
185
+ ```
186
+
187
+ <%= f.fields_for :category do |category| %>
188
+
189
+ <%= collection_check_boxes :user_categories_attributes, :category_ids, Category.all, :id, :name %>
190
+
191
+ <% end %>
192
+
193
+ ```
194
+
195
+ 上記により以下のパラメーターが取得できた
196
+
197
+
198
+
199
+ ```
200
+
201
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"/wvgHWAqbewmsqXQ4UIrr8WDiafgQMAI07GL5dvdpV7KgvklrsyVajNAYWcwWVI6+TZ9BEh+oC4mkPNqyxumUg==", "user"=>{"name"=>"test18", "email"=>"test18@aaa.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "birthday(1i)"=>"1986", "birthday(2i)"=>"1", "birthday(3i)"=>"7", "gender"=>"1"}, "user_categories_attributes"=>{"category_ids"=>["", "2", "3", "6"]}, "commit"=>"次へ"}
202
+
203
+ ```
204
+
205
+ が保存できないのでやはりストロングパラメーターの設定がおかしいのかもしれません
206
+
207
+ ###
208
+
209
+ ```
210
+
211
+ f configure_permitted_parameters
212
+
213
+ devise_parameter_sanitizer.permit(:sign_up) do |user_params|
214
+
215
+ user_params.permit({ roles: [] },:email,:password,:password_confirmation,:name, :birthday, :gender,user_categories_attributes: [category_ids:[] ])
216
+
217
+ end
218
+
219
+ end
220
+
221
+ ```

1

初心者マーク記載

2018/01/25 09:22

投稿

shohike
shohike

スコア8

test CHANGED
File without changes
test CHANGED
File without changes