このようなエラーが出たので、調べているとどうやらStrongParametersについてのエラーらしく、
まとめると、
「不正なデータが送信されないようにStrongParametersがあり、このエラーを解決するには、送信されたparamsの値をコントローラーで許可しなくてはいけい」という解釈にいたり、
デベロッパーツールの検証から、送られてくるparamsの値を調べたところ、
utf8:✓ authenticity_token:3MwvJMDcs8yrT/Ol4xTKiCmkNAPKL6XnFszauleZscPiHFw30igsERIlbnf0VnhlKDag77q3p8FZNlxhMgkWFg== post[title]: post[body]: post[image_file_name]: post[image_content_type]: post[image_file_size]: post[image_updated_at(1i)]: post[image_updated_at(2i)]: post[image_updated_at(3i)]: post[image_updated_at(4i)]: post[image_updated_at(5i)]: commit:Create Post
このような中身だったので、以下のように
postコントローラーの中身(permit以下)に追加しましたがエラーが消えません。
class PostsController < ApplicationController def index @posts=Post.all.order("created_at desc") end def show @post=Post.find(params[:id]) @post=Post.order("created_at desc").limit(4).offset(1) end private def post_params params.require(:post).permit(:title, :body, :image_file_name, :mage_content_type, :image_file_size,(1i), :image_updated_at(1i),:image_updated_at(2i), :image_updated_at(3i), :image_updated_at(4i), :image_updated_at(5i)) end end
そもそも、「image_file_size,(1i)」この書き方が正しいのかわかりませんし、StrongParametersの解釈、解決へのアプローチが正しいのかも自信ありません。
わかるかたがいらっしゃれば、ご教授ください。
あなたの回答
tips
プレビュー