【问题标题】:Error while using has_secure_password. cannot load such file -- 2.0/bcrypt_ext使用 has_secure_password 时出错。无法加载此类文件 -- 2.0/bcrypt_ext
【发布时间】:2013-09-08 15:45:27
【问题描述】:

我是 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' 但它仍然不起作用。

我在类似的问题中读到它与“捆绑安装”有关,但我无法解决问题。

提前致谢

【问题讨论】:

    标签: ruby-on-rails bcrypt-ruby bundle-install


    【解决方案1】:

    确实,

    gem install bcrypt-ruby 
    

    这将使has_secure_password 工作。还记得在看到更改后重新启动 rails 服务器。

    【讨论】:

    • 重新启动 rails 服务器为我解决了这个问题。谢谢。
    【解决方案2】:

    我们只能想象您使用的是什么平台,但我假设是 *nix 衍生产品。 编辑您的 Gemfile 是不够的 - bundle install 命令将为您完成这项工作。 您还需要安装本机编译工具链,因为bcrypt_ruby 在安装期间正在构建一些本机扩展。

    【讨论】:

      【解决方案3】:

      也许你正在使用 RVM 如果是这样你应该为 global gemset 安装 bcrypt gem:

      rvm gemset use global
      gem install bcrypt
      rvm gemset use whatever_gemset_you_use_previously
      

      (我使用bcrypt 而不是bcrypt-ruby,因为后者的弃用消息)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-21
        相关资源
        最近更新 更多