我正在尝试通过以下方法使用 Rails 控制台创 build 计用户
User.create!({:email => "abc@gmail.com", :roles => ["admin"], :password => "abc123", :password_confirmation => "abc123" })
我无法理解用户是否已创建。在我按下回车命令后,我没有得到任何回应。我执行了 user.save
然后执行了 u.all
但它什么也没显示,我无法登录。
请指出错误之处。
编辑:我也在下面尝试,但它不起作用
@user = User.new(:email => 'test@example.com', :password => 'password', :password_confirmation => 'password')
@user.save
谢谢
最佳答案
更新: 您缺少 User.new() 中的 {}
user = User.new({email: 'test@example.com', password: 'password', password_confirmation: 'password'})
user.save
你有 :confirmable 选项吗?如果是,请执行:
user = User.new({email: 'test@example.com', password: 'password', password_confirmation: 'password'})
user.skip_confirmation!
user.save
关于ruby-on-rails - 从 Rails 控制台设计用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909643/