我是 Ruby on Rails 的新手,所以我正在学习使用 Rails 4 进行敏捷 Web 开发教程。但是在用户身份验证方面,我遇到了一个无法解决的错误... 我制作了一个表单,以便用户可以登录,为此我在文件 user.rb 中使用 has_secure_password:
class User < ActiveRecord::Base
has_secure_password
validates :name, presence: true, uniqueness: true
end
但是当我运行服务器时出现错误:
cannot load such file -- 2.0/bcrypt_ext
这是应用程序跟踪
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
我在 gemfile 中包含了 gem 'bcrypt-ruby', '~> 3.0.0' 但它仍然不起作用。
我在类似的问题中读到它与“捆绑安装”有关,但我无法解决问题。
提前致谢
最佳答案
当然,
gem install bcrypt-ruby
这将使has_secure_password
工作。另请记住在看到更改后重新启动 Rails 服务器。
关于ruby-on-rails - 使用 has_secure_password 时出错。无法加载此类文件——2.0/bcrypt_ext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18685549/