【问题标题】:Is it possible to seed users into the DB with the Clearance gem?是否可以使用 Clearance gem 将用户播种到数据库中?
【发布时间】:2018-05-31 17:37:40
【问题描述】:

我正在开发一个使用 Clearance gem 进行身份验证的 Ruby-on-Rails 项目。有没有办法使用 seed.rb 文件将用户播种到我的数据库中,还是我必须在登录页面上手动创建用户?看起来用户表是使用加密密码属性构造的,所以我不确定如何进行播种。

【问题讨论】:

    标签: ruby-on-rails clearance


    【解决方案1】:

    文档并没有说你必须做任何花哨的事情。

    def create_user(email)
      User.create!(
        email:  email,
        password: "password1234"
      )
    end
    
    #fake  users
    1...50.times do |i|
      create_user("person_#{i}@test#{i}.io")
    end
    

    在控制台中

      User.last
      => <User id: 50, created_at: "2018-05-31 18:51:57", updated_at: "2018-05-31 18:51:57", email: "person_49@test49.io", encrypted_password: "$2a$10$JBWpdFocyd1TTBy5W30uYuWaD5nTo1TPErtQpt2nNZO...", confirmation_token: nil, remember_token: "cfaf107ea30d3303bb991f61973368b2a1fd44c7">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2022-10-18
      • 2020-11-28
      相关资源
      最近更新 更多