Rails 4 and Active Admin: ActiveModel :: ForbiddenAttributesError

The complete error is as follows:

ActiveModel::ForbiddenAttributesError in Admin::ProductsController#create

My product model has only nameand price. Why commitparameter? When I click the Create Product button in the admin control panel, this is the output of the parameters:

Parameters:

{"utf8"=>"โœ“",
 "authenticity_token"=>"6/pCeklsaik4sYF5h8+WRPddkH7wJn9ZJHd6YLaaNuc=",
 "product"=>{"name"=>"Black Shirt Male",
 "price"=>"25"},
 "commit"=>"Create Product"}

From what I compiled by reading other stack overflow messages, you need to use strong parameters in Rails 4 instead of attr_accessiblewhat was done for me when I drew the product model. In my action createon the Products controller, I:

@product = Product.new(product_params)

And product_params is defined as:

def product_params
  params.require(:product).permit(:name, :price)
end

I did not do anything unusual when I created the model, and in my Gemfile I use the following as the documentation suggested for Rails 4:

gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'

Active Admin? .

+4
2

, . , "" , .

app/admin/product.rb :

permit_params :list, :of, :attributes, :on, :model, :name, :price

permit_params :list, :of, :attributes, :on, :model

. :name :price

+11

Source: https://habr.com/ru/post/1532578/


All Articles