Disclaimer: I'm using Rails 3.2. Specifically, in the Rails 3 in Action book:
The User model does have attr_accessible attr_accessible :email, :password, password_confirmation, :remember_me
The User model NOT have :admin listed, therefore it can't be mass-assigned to as part of params[:user].
The form_for block inside app/views/admin/users/_form.html.erb sets up a checkbox element to allow an admin to set a user as an admin:
` <%= f.check_box :admin %> <%= f.label :admin, "Is an admin?" %>
The app/controllers/admin/users_controller.rb
@user = User.new(params[:user])
@user.admin = params[:user][:admin] == "1"
if @user.save
The line @user.admin = params[:user][:admin] == "1" should set the admin attribute to true, but generates mass-assignment errors which prevent me from changing the @user.admin attribute to true.
I can set the admin attribute to true without mass-assigning via the console, along with defining a method in the User model:
def make_admin
self.admin = true
end
This accomplishes the same thing, nothing fancy.
How do I get the admin attribute assigned to TRUE for the user to work using a view & controller via the checkbox?
Is there a way to remove or separate the admin parameter from params[:user][:admin])?