ActiveModel::ForbiddenAttributesError in UsersCont

2019-08-16 19:01发布

问题:

I know this has been asked a million times before but the suggested solutions didn't fix anything for me.

def create
@user = User.new(user_params)   
if @user.save
else
  render 'new'
end
end

At first I had these params:

private

def user_params
 params.require(:user).permit(:firstname, :name, :email, :password,
                             :password_confirmation, role_ids: [])
end

Then I tried allowing every param:

private

def user_params
 params.require(:user).permit!
end

However, the result is the same:

ActiveModel::ForbiddenAttributesError in UsersController#create

  def sanitize_for_mass_assignment(attributes)
    if attributes.respond_to?(:permitted?) && !attributes.permitted?
      raise ActiveModel::ForbiddenAttributesError
    else
      attributes
    end

What am I missing?!

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

Rails 4.2.2

回答1:

Alright so here we go, I had a messed up gem file installed. Problem Solved.