Rails, DEVISE - Preventing a user from changing their email address -


when user registers on app have confirm email, powered devise + rails 3.

the email address defines user's permissions don't want user able change once registered. removed :email users.rb attr_accessible worked logged in user, user's can't register.

what's right way handle this? users can't update email can register email using devise.

thanks

this perfect case custom validator. since rails3, easier before.

class immutablevalidator < activemodel::eachvalidator   def validate_each(record, attribute, value)     record.errors[attribute] << "cannot changed after creation" if record.send("#{attribute}_changed?") && !record.new_record?   end end  class user < activerecord::base   validates :email, :immutable => true end 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -