Answer the question
In order to leave comments, you need to log in
Why does the error "Can't mass-assign protected attributes for" appear on save after migrating to Rails 4 in Rails Admin?
The problem is that earlier I wrote something like this in models: attr_accessible :name, :value, :var, as: :admin
and I wrote in rails_admin.rb config.attr_accessible_role { :admin }
But with the new version, the attr_accessible_role method was removed. I understand that RoR 4 uses strong parameters. But I didn't want to change a lot of code, so I just added the 'protected_attributes' gem. But there was a problem with the Rails admin when saving, it gives an error:
Can't mass-assign protected attributes for.
Answer the question
In order to leave comments, you need to log in
The bottom line is that the attributes that can be edited in batches must be defined in the controller, not in the model.
To get rid of your error, call the permit method on the params hash in the controller and pass it a list of editable attributes. More or less like this:
class PeopleController < ApplicationController
def create
Person.create(person_params)
end
private
def person_params
params.require(:person).permit(:name, :age)
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question