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

質問編集履歴

2

モデルについて追記

2017/05/18 13:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -23,10 +23,31 @@
23
23
  params.require(:article).permit(:title, :description, :main_image,article_chapter_blocks_attributes: [:id, :title, :_destroy, {article_chapter_text_parts_attributes: [:id, :title, :description, :_destroy]}])
24
24
  end
25
25
  ```
26
- モデルの関係
26
+ モデル
27
+ ```ruby
27
- article 1- article_chapter_block 1-多 article_chapter_text_parts
28
+ class ArticleChapterTextPart < ActiveRecord::Base
29
+ belongs_to :article_chapter_block
30
+ belongs_to :article
31
+ end
28
32
 
33
+ class Article < ActiveRecord::Base
34
+ has_many :article_chapter_blocks
29
- article 1- 多 article_chapter_text_parts
35
+ has_many :article_chapter_text_parts
30
36
 
37
+ accepts_nested_attributes_for :article_chapter_blocks, allow_destroy: true
31
38
 
39
+ #carrierwave
40
+ mount_uploader :main_image, AriticleImageUploader
41
+ end
42
+
43
+ class ArticleChapterBlock < ActiveRecord::Base
44
+ belongs_to :article
45
+
46
+ has_many :article_chapter_text_parts
47
+ end
48
+ ```
49
+
50
+ 今回は、Nested Formのgemを使ってformから更新しようとしてます。
51
+
52
+
32
53
  何時間も悩んでもできなかったので、誰か助けてください。お願いします。

1

タグの追加

2017/05/18 13:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes