今、rails4の開発を行っています。
その中のでなぜかこのパラメータに対する StrongParameterができず、モデルの作成、更新ができずにいます。
わかる方いたら、回答をお願いします。
"article"=>{"title"=>"ssddddddddddddddd", "description"=>"asas", "article_chapter_blocks_attributes"=>{"0"=>{"_destroy"=>"false", "title"=>"ddd", "article_chapter_text_parts"=>{"title"=>"ddddd", "content"=>"", "_destroy"=>""}, "id"=>"3"}}}
ruby
1 def create 2 article = Article.new(article_params) 3 if article.save 4 redirect_to action: "index" 5 else 6 redirect_to :back 7 end 8 end 9 10private 11 def article_params 12 params.require(:article).permit(:title, :description, :main_image,article_chapter_blocks_attributes: [:id, :title, :_destroy, {article_chapter_text_parts_attributes: [:id, :title, :description, :_destroy]}]) 13 end
モデル
ruby
1class ArticleChapterTextPart < ActiveRecord::Base 2 belongs_to :article_chapter_block 3 belongs_to :article 4end 5 6class Article < ActiveRecord::Base 7 has_many :article_chapter_blocks 8 has_many :article_chapter_text_parts 9 10 accepts_nested_attributes_for :article_chapter_blocks, allow_destroy: true 11 12 #carrierwave 13 mount_uploader :main_image, AriticleImageUploader 14end 15 16class ArticleChapterBlock < ActiveRecord::Base 17 belongs_to :article 18 19 has_many :article_chapter_text_parts 20end
今回は、Nested Formのgemを使ってformから更新しようとしてます。
何時間も悩んでもできなかったので、誰か助けてください。お願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。