Seeding users with Devise in Ruby on Rails

后端 未结 14 2444
终归单人心
终归单人心 2020-12-14 00:59

In my development and test environments, I want to seed the database with a bunch of users. I\'m using Ruby on Rails v3.2.8 and the latest Devise. So I added this line in

14条回答
  •  情歌与酒
    2020-12-14 01:40

    If you're using the devise confirmable module you need to do something like:

    user = User.new(
      email: 'user@domain.com', 
      password: '123456789', 
      password_confirmation: '123456789'
    )
    user.skip_confirmation!
    user.save!
    

    The skip_confirmation! call just tell to devise that you don't need to confirm this account.
    Other option is just set the confirmed_at user attribute as Time.now.utc before save.

提交回复
热议问题