带有Rails的{bcrypt LoadError

时间:2017-11-27 23:46:37

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

我无法找到解决此问题的方法,并尝试了许多其他人遇到的修复但没有成功。我正在研究Michael Hartl的Ruby on Rails 5教程,它需要使用bcrypt来实现has_secure_password功能。当我运行测试时,我收到一条长错误消息,该消息以:

开头
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in 'require': cannot load such file -- bcrypt_ext (LoadError)

我尝试卸载并重新安装bcrypt,最后添加--platform=ruby并在gemfile中包含各种版本; gem 'bcrypt', '~> 3.1.7''bcrypt', '3.1.11', platforms: [:ruby, :x64_mingw]'bcrypt', '~> 3.1.7', platforms: [:ruby]包括从命令行安装gem文件的各种组合。从控制台安装时,保留gem文件,只需使用gemfile链接卸载并运行Bundle Install。

这是我在尝试访问Rails控制台时收到的整个错误消息:

C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in 'require': cannot load such file -- bcrypt_ext (LoadError)
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in `rescue in <top (required)>'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:12:in `<top (required)>'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:81:in `require'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:81:in `block (2 levels) in require'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:76:in `each'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:76:in `block in require'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:65:in `each'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:65:in `require'
    from C:/Ruby23-x64/lib/ruby/site_ruby/2.3.0/bundler.rb:114:in `require'
    from C:/Users/Bill/Documents/Sites/sample_app/config/application.rb:7:in `<top (required)>'
    from C:/Ruby23x64/lib/ruby/gems/2.3.0/gems/railties-.1.4/lib/rails/command/actions.rb:15:in `require'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/console/console_command.rb:96:in `perform'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in`run'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我使用的是Ruby版本2.3.3,在Windows 7x64上运行Rails版本5.1.4。

任何人都可以提供给我的任何见解将不胜感激。

更新

因此,在尝试解决问题的无数个小时之后,使用gemfile:

gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'

是什么解决了我的问题。这可能不是一个永久的解决方案,但至少它让我向前迈进!

0 个答案:

没有答案