ActiveAdmin ForbiddenAttributesError
Rails 4
uses strong parameters, which moves attribute whitelisting from the model to the controller. It is necessary to specify the attributes that you would like to be saved in the database. You have not permitted the attributes in your code, which is why you are receiving the ActiveModel::ForbiddenAttributesError
.
Refer to the documentation of ActiveAdmin : Setting up Strong Parameters
You can setup strong parameters in the following way, using permit_params
method which creates a method called permitted_params
, use this method when overriding create
or update
actions:
ActiveAdmin.register AdminUser do
## ...
permit_params :attr1, :attr2 ## Add this line
end
Replace :attr1
, :attr2
, etc with the actual attribute names that you want to whitelist. For example: :email
ForbiddenAttributesError with Active Admin
I think you didn't add permit_params
in your active admin file.
# app/admin/xyz.rb
permit_params :comma separated attributes.
Look into this link for more detail.
Rails 4 and Active Admin: ActiveModel::ForbiddenAttributesError
Alright figured it out. I'm not sure if this is the 'correct' way but the products are being created.
in app/admin/product.rb I did:
permit_params :list, :of, :attributes, :on, :model, :name, :price
where
permit_params :list, :of, :attributes, :on, :model
was initially commented out. So I just added :name
and :price
ActiveModel::ForbiddenAttributesError showing even when I've added all of the attributes to the strong parameters
I had a typo on the permit_params declaration. I just removed the equal sign.
wrong:
permit_params = :prefix, :firstname, :lastname, :password, :email, :membership_code, :birthdate, :contact_number, :location, :active, :confirmed, :remember_token, :town, :province
right:
permit_params :prefix, :firstname, :lastname, :password, :email, :membership_code, :birthdate, :contact_number, :location, :active, :confirmed, :remember_token, :town, :province
Thanks! @nistvan
ActiveModel::ForbiddenAttributesError within Active Admin
I was missing
controller do
def permitted_params
params.permit event: [:venue, :trainer_id, :description, :training_request_id, :title, :date]
end
end
inside ActiveAdmin.register Event do
Can't update resource from ActiveAdmin interface -- ActiveModel::ForbiddenAttributesError
Solved it by adding this to admin/thing.rb
controller do
def permitted_params
params.permit thing: [ :title, :description, :image_file_name, :image_content_type, :image_file_size, ":image_updated_at(1i)", ":image_updated_at(2i)", ":image_updated_at(3i)", ":image_updated_at(4i)", ":image_updated_at(5i)" ]
end
Related Topics
Use Separate Authentication Model with Devise on Rails
Ruby, Tor and Net::Http::Proxy
Ruby - Difference Between :Variable and @Variable
Why Doesn't Module.Method_Defined(:Method) Work Correctly
Safe Navigation Equivalent to Rails Try for Hashes
Are There Any Good Mutation Testing Tools for Ruby 1.9 and Rspec2
Delete Non-Utf Characters from a String in Ruby
How to Access the Base Namespace in Ruby
What Is the Point of Object#Presence in Rails
Convert 12 Hr Time to 24 Hr Format in Ruby
Ruby on Rails - Paperclip and Dynamic Parameters
Solving the Travelling Salesman Problem in Ruby (50+ Locations)
Rails: Update Model Attribute Without Invoking Callbacks
Built in Way to List Directories in a Directory in Ruby
How to Detect the End of a Method Chain in Ruby
Can Activerecord Connect to Postgresql Remotely and Protect the Db Password