For the implementation of the basic model admin, we have created a file that can modify ModelName as follows.
ActiveAdmin.register ModelName do
menu priority: 2, label: 'aaa', parent: 'bbb'
end
It goes well to the editing screen, but when I try to create a new record, ActiveModel::ForbiddenAttributesError occurs.
ActiveModel::ForbiddenAttributesError
/Users/@@/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activemodel-4.2.6/lib/active_model/forbidden_attributes_protection.rb:21:in sanitize_for_mass_assignment'
/Users/@@/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activerecord-4.2.6/lib/active_record/attribute_assignment.rb:33:in
assign_attributes'
Why is it like this?
ruby-on-rails activeadmin
Rails 4 uses strong parameters so if an attribute is not allowed,
ActiveModel::ForbiddenAttributesError
appears.
Therefore, you must include permit_params
in ActiveAdmin.
ActiveAdmin.register ModelName do
permit_params : attr1, :attr2, :etc//<-- Add this line.
// Replace attr1 and attr2 with the actual attribute name.
end
© 2024 OneMinuteCode. All rights reserved.