0

ActiveModel::ForbiddenAttributesError Extracted source (around line #3):

  1. def create
  2. @post = Post.find(params[:post_id])
  3. @comment = @post.comments.create!(params[:comment])
  4. redirect_to @post
  5. end
  6. end

Rails.root: C:/Users/ManU/Desktop/quick_blog Application Trace | Framework Trace | Full Trace

app/controllers/comments_controller.rb:4:in `create'

What i'm supposed to do to deal with this error..... please give me soln with path as well...i don't have prior knowlwdge to this.....

2

2 Answers 2

8

you appear to be following a pre rails 4.0 tutorial with rails 4. You need to use strong params now.

http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters

there is also a railscast on it that should help.

@comment = @post.comments.create!(params.require(:comment).permit!) 


@comment = @post.comments.create!(params.require(:comment).permit(:comment_text,:link))

The first will permit all params to be allowed, the latter will only allow comment_text and link to be accepted.

2
  • You are missing the closing braces of the .create! methods. Commented Jan 29, 2015 at 16:36
  • Thanks ..I'm begginer and had suspect be a problem relation of Strong Params, so your answer helped a lot. Commented Jan 24, 2016 at 14:17
1

If the system is throwing ActiveModel::ForbiddenAttributesError, that means you must be using strong_parameters gem or your rails should have version greater than 4, in which case strong_parameters gem is already included in that version. In that case, you add the following code on your application_controller.rb to get rid off from this error.

before_filter do
  resource = controller_name.singularize.to_sym
  method = "#{resource}_params"
  params[resource] &&= send(method) if respond_to?(method, true)
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.