当我将has_secure_password添加到模型(继承自ActiveRecord::Base)时,出现错误,声明"bcrypt-ruby不是捆绑包的一部分“。
这里的日志是:
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
$ 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",这个错误不会出现。
我该如何解决这个问题?
发布于 2012-02-19 16:05:18
正如消息所说,您需要将bcrypt-ruby添加到Gemfile (在项目的根目录下)。
添加
gem "bcrypt-ruby"然后运行bundle install就可以了(如果您还没有安装它,这将获取gem )。
您可以指定特定的版本,例如
gem "bcrypt-ruby", "~> 3.0.1"将为您提供>=到3.0.1但低于3.1的最新版本。如果3.0.1有一个你依赖的bug修复,并且你很高兴得到更多的bug修复,但你不想要重大的改变,你可能会这样做。在bundler网站上有更多的信息。
发布于 2012-07-24 00:48:50
我在Gemfile中已经有了gem 'bcrypt-ruby', '~> 3.0.0',并且已经运行了命令bundle,但是我仍然收到了这条消息。问题是我忘了重启服务器:
touch tmp/restart.txt发布于 2012-02-19 16:01:54
在Gemfile中添加一行
gem 'bcrypt-ruby'然后从命令行
bundle installhttps://stackoverflow.com/questions/9347599
复制相似问题