Nested Form Gemを使って、formを作成しています。
なのですが、 f.fields_forがうまく表示されず困っています。
なにかアドバイスをください。
ruby
1= nested_form_for(@article, url: admin_articles_path, multiple: true) do |f| 2 .form-group 3 = f.label :title, "タイトル" 4 = f.text_field :title, class: "form-control" 5 .form-group.main-image-box 6 = f.label :main_image, "メイン画像" 7 = f.file_field :main_image, multiple: true 8 = image_tag("", class: "main-image") 9 .form-group 10 = f.label :description, "記事の説明" 11 = f.text_area :description, class: "form-control" 12 .form-group.article_chapter 13 = f.fields_for :article_chapter_blocks do |article_chapter_blocks_form| 14 = render "article_chapter_block", f: article_chapter_blocks_form 15 = f.link_to_add "追加", :article_chapter_blocks,data: {target: ".article_chapter"} 16 17 = submit_tag "登録", class: "btn btn-default"
_article_chapter_block.html.slim
ruby
1= f.link_to_remove "このブロックを削除" 2.form-group 3 = f.label :description, "大見出し" 4 = f.text_field :title, class: "form-control" 5.form-group 6 = f.fields_for :article_chapter_text_parts do |article_chapter_text_parts_form| 7 = render "article_chapter_text_parts", f: article_chapter_text_parts_form
_article_chapter_text_parts.html.slim
ruby
1= f.label :title, "小見出し" 2= f.text_field :title, class: "form-control" 3= f.label :content, "内容" 4= f.text_area :content, class: "form-control" 5= f.link_to_remove "削除"
モデル
ruby
1class Article < ActiveRecord::Base 2 has_many :article_chapter_blocks 3 4 accepts_nested_attributes_for :article_chapter_blocks, allow_destroy: true 5 #carrierwave 6 mount_uploader :main_image, AriticleImageUploader 7end 8 9class ArticleChapterBlock < ActiveRecord::Base 10 belongs_to :article 11 12 has_many :article_chapter_text_parts 13 accepts_nested_attributes_for :article_chapter_text_parts, allow_destroy: true 14end 15 16class ArticleChapterTextPart < ActiveRecord::Base 17 belongs_to :article_chapter_block 18end
何時間も考えて解決できなかったのでよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。