LxS*_*iss 2 ruby-on-rails bundle-install bcrypt-ruby
我是 Ruby on Rails ans 的新手,所以我正在学习 Rails 4 敏捷 Web 开发教程。所以用户可以登录,为此我在文件 user.rb 中使用了 has_secure_password:
class User < ActiveRecord::Base
has_secure_password
validates :name, presence: true, uniqueness: true
end
Run Code Online (Sandbox Code Playgroud)
但是当我运行服务器时,我收到错误:
cannot load such file -- 2.0/bcrypt_ext
Run Code Online (Sandbox Code Playgroud)
这是应用程序跟踪
app/models/user.rb:2:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/users_controller.rb:7:in `index'
This error occurred while loading the following files:
bcrypt
bcrypt_ext
2.0/bcrypt_ext
Run Code Online (Sandbox Code Playgroud)
我在 gemfile 中包含 gem 'bcrypt-ruby', '~> 3.0.0' 但它仍然不起作用。
我在类似的问题中读到它与“捆绑安装”有关,但我无法解决问题。
提前致谢
小智 5
确实,
gem install bcrypt-ruby
Run Code Online (Sandbox Code Playgroud)
这将使has_secure_password工作。还记得在看到更改后重新启动 rails 服务器。