开发者

Devise - Prevent email update attribute [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜