I am using devise for authenticating users. I have defined a score for a user that is updated over time. A separate controller takes care of updating the score. I use @user.update_attributes(:score => new_score) but the changes can’t be saved. I am suspicious that is happening because user is a devise object.
Can someone help me figure this out?
Thanks a lot
With Devise you probably have an
attr_accessibleline in your User model. This is a whitelist of attributes which can be updated via bulk assignment from hashes (with methods like update_attributes). You can do one of two things:add :score to
attr_accessible. This means that by default POSTing to the user edit screen with params[:user][:score] = x will update the user’s score.assign the score directly in your controller, via
@user.score = x. Direct assignment is not affected byattr_accessibleHere’s the doc: http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_accessible