从 Ruby 控制台创建一个设计用户 [英] Create a devise user from Ruby console

查看:17
本文介绍了从 Ruby 控制台创建一个设计用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何使用来自 ruby​​ 控制台的设计创建和保存新用户对象的任何想法?

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 something but I'm unable to find any related info.

推荐答案

如果需要,您可以向 save 方法添加 false 以跳过验证.

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)

否则我会这样做

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

如果您为设计启用了 confirmable 模块,请确保在创建时将 confirmed_at 值设置为类似 Time.now 的值.

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

这篇关于从 Ruby 控制台创建一个设计用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆