Create a devise user from Ruby console

前端 未结 5 1346
广开言路
广开言路 2020-12-04 04:48

Any idea on how to create and save a new User object with devise from the ruby console?

When I tried to save it, I\'m getting always false. I guess I\'m missing some

5条回答
  •  抹茶落季
    2020-12-04 05:48

    You can add false to the save method to skip the validations if you want.

    User.new({:email => "guy@gmail.com", :roles => ["admin"], :password => "111111", :password_confirmation => "111111" }).save(false)
    

    Otherwise I'd do this

    User.create!({:email => "guy@gmail.com", :roles => ["admin"], :password => "111111", :password_confirmation => "111111" })
    

    If you have confirmable module enabled for devise, make sure you are setting the confirmed_at value to something like Time.now while creating.

提交回复
热议问题