Seeding users with Devise in Ruby on Rails

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'

Leave a Comment