Seeding users with Devise in Ruby on Rails

后端 未结 14 2471
终归单人心
终归单人心 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:28

    You have to do like this:

    user = User.new
    user.email = 'test@example.com'
    user.encrypted_password = '#$taawktljasktlw4aaglj'
    user.save!
    

    Read this guide to understand what mass-assignment is: http://guides.rubyonrails.org/security.html

    I am wondering why do have to directly set the encrypted password. You could do this:

    user.password = 'valid_password'
    user.password_confirmation = 'valid_password'
    

提交回复
热议问题