Devise - Prevent email update attribute [duplicate]
Possible Duplicate:
Rails, DEVISE - Prevent开发者_运维技巧ing a user from changing their email address
How do I go about preventing the user from updating their email field? I have a pretty generic devise setup. I was thinking maybe I could do a general validation check on update in the model. But perhaps there is a better way to do this.
validate :prevent_email_change, :on => :update
I haven't worked much with devise so I can't say for sure if there's a built in way to do this, but normally you use Rails' methods for protecting specific attributes. The safest way to do this is with attr_accessible, but you can also use attr_protected if you don't anticipate that your model's attributes will change.
In your case, your User model would include the line:
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name, :blah, :blah, :blah
end
Note that :email is not listed here since you do not want it to be accessible.
精彩评论