开发者

Custom Changes in User Model with Devise

开发者 https://www.devze.com 2023-02-23 06:00 出处:网络
i\'m using Devise for registrations. Devise uses my User model to create new users. However, i want to add some custom values to the user model upon registration. I thought something like a before_cre

i'm using Devise for registrations. Devise uses my User model to create new users. However, i want to add some custom values to the user model upon registration. I thought something like a before_create filter on the User model, but i'm not sure that is the b开发者_运维技巧est choice.

How would you do it ? (without hidden form fields, i need to customize more than that)


You can add any attribute/field to a Devise authentication table like you do for other table in the database. If its not about validating data, use after_create

Update:

Like if you want to add extra field full_name comprised of first_name and last_name, you can write

after_create :populate_full_name

def populate_full_name
    self.full_name = "#{self.first_name} #{self.last_name}"
end
0

精彩评论

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