I'm getting an error when sending a post request to my comments controller using form_for([@post, @comment]). To create a comment.
ActiveModel::ForbiddenAttributesError in CommentsController#create
Line causing the error:
@comment = @post.comments.build(params[:comment])
I know that it is down to a strong parameters issue but I can't seem to get it right. At the moment my model for posts is:
posts.rb
class Post < ActiveRecord::Base
has_many :comments, dependent: :destroy
end
And for comments:
comment.rb
class Comment < ActiveRecord::Base
belongs_to :post
end
My current strong parameters setup for the comments controller is:
comments_controller.rb
private
def comment_params
params.require(:post).permit(comment: [:name, :body])
end
And finally parameters as being reported by the error message are:
{"utf8"=>"✓",
"authenticity_token"=>"MSX1PrrvfzYBr/DNYaMgSw3opWmaJs82xd11JfLPIqI=",
"comment"=>{"name"=>"",
"body"=>""},
"commit"=>"Create Comment",
"post_id"=>"1"}
Anyone got any ideas where my strong params setup is broken - any ideas would be greatly appreciated. Thanks!