Reputation: 87
ActiveModel::ForbiddenAttributesError Extracted source (around line #3):
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.....
Upvotes: 0
Views: 3262
Reputation: 20232
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.
Upvotes: 8
Reputation: 802
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
Upvotes: 1