我是 Rails 新手,学习 Rails 5.1 的 Agile Rails Web Development 教程。我正在使用导轨 5.2
我创建了用户:
rails g scaffold User name:string password:digest
rails db:migrate
class User < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_secure_password
end
所有用户测试都失败了:
NameError: uninitialized constant ActiveRecord::FixtureSet::RenderContext::BCrypt
test/fixtures/users.yml:5:in `get_binding'
这是夹具文件:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: dave
password_digest: <%= BCrypt::Password.create('secret') %>
two:
name: susannah
password_digest: <%= BCrypt::Password.create('secret') %>
github链接:https ://github.com/marko-avlijas/depot
我不知道如何调试这个并且谷歌搜索错误并没有给我任何东西。
如果我require 'bcrypt'
输入 test_helper 我得到:
`require': 无法加载此类文件 -- bcrypt (LoadError)
bo-oz 建议我将 BCrypt::Password.create('secret') 粘贴到控制台中并在固定装置中使用它。但即使这样也行不通。通过网络界面,我可以创建新用户,服务器输出表明没有错误,但在控制台中我得到了这个:
>> BCrypt::Password.create('secret')
NameError: uninitialized constant BCrypt
from (irb):1
>> require 'bcrypt'
LoadError: cannot load such file -- bcrypt
from (irb):2