错误指出“bcrypt-ruby 不是捆绑包的一部分",我如何将 bcrypt-ruby 添加到 Gemfile? [英] Error stating that "bcrypt-ruby is not part of the bundle", how can I add bcrypt-ruby to Gemfile?

查看:42
本文介绍了错误指出“bcrypt-ruby 不是捆绑包的一部分",我如何将 bcrypt-ruby 添加到 Gemfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 has_secure_password 添加到模型(从 ActiveRecord::Base 继承)时,会出现错误指出bcrypt-ruby 不是捆绑包的一部分".

When I add has_secure_password to the model (inherited from ActiveRecord::Base), error stating that "bcrypt-ruby is not part of the bundle" occurs.

这里的日志是:

Started GET "/users" for 127.0.0.1 at 2012-02-19 16:37:12 +0900

Gem::LoadError (bcrypt-ruby is not part of the bundle. Add it to Gemfile.):
app/models/user.rb:3:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/users_controller.rb:1:in `<top (required)>'

我安装了 bcrypt-ruby

I installed bcrypt-ruby by

$ gem install bcrypt-ruby
Building native extensions.   This could take a while...
1 gem installed
Installing YARD (yri) index for bcrypt-ruby-3.0.1...
Installing RDoc documentation for bcrypt-ruby-3.0.1...

但是没有用.

我试过了

$ bundle exec rails server

但没有帮助.

如果我注释掉has_secure_password"这一行,就不会出现这个错误.

If I comment out the line "has_secure_password", this error does not come out.

我该如何解决这个问题?

How can I solve this problem?

推荐答案

正如消息所说,您需要将 bcrypt-ruby 添加到您的 Gemfile(在项目的根目录).

As the message says you need to add bcrypt-ruby to your Gemfile (at the root of the project).

添加

gem "bcrypt-ruby"

然后运行 ​​bundle install 应该可以解决问题(如果您还没有安装它,这将获取 gem).

and then running bundle install should do the trick (this would fetch the gem if you hadn't already installed it).

您可以指定特定版本,例如

You can specify specific versions to, eg

gem "bcrypt-ruby", "~> 3.0.1"

将为您提供 >= 到 3.0.1 但小于 3.1 的最新版本.如果 3.0.1 有一个您依赖的错误修复并且您很高兴获得更多错误修复但您不希望进行重大更改,则您可以这样做.bundler 网站上有更多信息.

will get you the latest version that is >= to 3.0.1 but less than 3.1. You might do this if 3.0.1 has a bug fix you depend on and you're happy to get more bug fixes but you don't want major changes. There's loads more info on the bundler website.

这篇关于错误指出“bcrypt-ruby 不是捆绑包的一部分",我如何将 bcrypt-ruby 添加到 Gemfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆