新手问题 (已解决) 新手求指点:NoMethodError: undefined method `cost' for BCrypt::Engine:Class

gsky · 2014年02月18日 · 最后由 gsky 回复于 2014年02月18日 · 5237 次阅读

我在练习 Ruby on Rails Tutorial 第 6 章,控制台手动创建新用户的时候,报这个错误,求高手指点一下:

NoMethodError: undefined method cost' for BCrypt::Engine:Class from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activemodel-4. 0.2/lib/active_model/secure_password.rb:104:inpassword=' from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4 .0.2/lib/active_record/attribute_assignment.rb:42:in public_send' from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4 .0.2/lib/active_record/attribute_assignment.rb:42:in_assign_attribute'

PS: 我用的 bcrypt-ruby 是 3.1.2 版本,不是教程里的 3.0.1 版本,因为在 Gem 里使用 3.0.1 版本时,会报冲突:

You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install Gem::LoadError: can't activate bcrypt-ruby (~> 3.1.2), already activated bcrypt- ruby-3.0.1-x86-mingw32. Make sure all dependencies are added to Gemfile. from D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/ lib/bundler/rubygems_integration.rb:224:in `block in replace_gem'

可能是我装的 railsinstaller 自带的 bcrypt-ruby 版本时 3.1.2....

已解决: 1 把 secure_password.rb 里的 gem 'bcrypt-ruby', '~> 3.0.0' 改成 gem 'bcrypt-ruby', '~> 3.1.0'1 2 项目文件夹里 Gemfile 里用 gem 'bcrypt-ruby', '3.1.2'。

windows 上面问题比较多,新手可以试试 nitrous+heroku

······没办法

需要 登录 后方可回复, 如果你还没有账号请 注册新账号