teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2020/05/16 01:20

投稿

winterboum
winterboum

スコア23654

answer CHANGED
@@ -14,4 +14,13 @@
14
14
  一つですか?
15
15
 
16
16
  Tagは一つしかつけられないのか、複数つけられるのかによって回答が変わります。
17
- どちらでしょう?
17
+ どちらでしょう?
18
+
19
+ ###ひとつだけなのでしたら
20
+ 0. Postのtagは tag_id(integer)に替える
21
+ 0. class Post のvalidates,has_many 3行は削除し`belongs_to :tag`にする
22
+ ただし、tag無しでも良しとするなら`belongs_to :tag, optional: true`
23
+ 0. ` form.collection_select :tags_ids,` は ` form.collection_select :tags_id,`
24
+ 0. `permit(:tag, :title, :text, :image)` は `permit(:tag_id, :title, :text, :image)`
25
+
26
+ で行けるかな