Create a devise user from Ruby console

前端 未结 5 1379
广开言路
广开言路 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:27

    When on your model has :confirmable option this mean the object user should be confirm first. You can do two ways to save user.

    a. first is skip confirmation:

    newuser = User.new({email: 'superadmin1@testing.com', password: 'password', password_confirmation: 'password'})
    newuser.skip_confirmation!
    newuser.save
    

    b. or use confirm! :

    newuser = User.new({email: 'superadmin2@testing.com', password: 'password', password_confirmation: 'password'})
    newuser.confirm!
    newuser.save
    

提交回复
热议问题