1

我从https://github.com/mhartl/rails_tutorial_3rd_edition_gemfiles/blob/master/sample_app/Gemfile获得了宝石

然后我收到一条错误消息,例如

C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bcrypt-3.1.7-x86-mingw32/li
b/bcrypt.rb:16:in `require': cannot load such file -- bcrypt_ext (LoadError)
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bcrypt-3.1.7-x
86-mingw32/lib/bcrypt.rb:16:in `rescue in <top (required)>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bcrypt-3.1.7-x
86-mingw32/lib/bcrypt.rb:12:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:76:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:76:in `block (2 levels) in require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:72:in `each'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:72:in `block in require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:61:in `each'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler/runtime.rb:61:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/
lib/bundler.rb:133:in `require'
        from C:/Projects/Mailbox/mailboxer-app/config/application.rb:14:in `<top
 (required)>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `server'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.4
/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
4

3 回答 3

1

这个问题是 Windows 特有的,在bcrypt-ruby issue: 72中得到解决。

更新你Gemfile为:

gem 'bcrypt-ruby', '3.1.1.rc1', :require => 'bcrypt'

然后

bundle install
于 2015-07-21T06:13:50.423 回答
1

只需按照此链接的步骤操作:这对我 有用 https://www.ambidev.com/loaderror-cannot-load-such-file-bcrypt_ext/

您应该正确安装和配置 DevKit 以重新编译 gem。

LoadError: cannot load such file -- bcrypt_ext

首先停止您的服务器并删除每个 bcrypt gem 或 bcrypt-ruby gem。

C:\>gem uninstall bcrypt
You have requested to uninstall the gem:
    bcrypt-3.1.10-x86-mingw32

bcrypt-ruby-3.1.5 depends on bcrypt (>= 3.1.3)
devise-3.5.2 depends on bcrypt (~> 3.0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled bcrypt-3.1.10-x86-mingw32

不要忘记在您的 Gemfile gem 'bcrypt' 中包含 bcrypt

进行捆绑更新并像这样重新编译gem

C:\<Ruby Path>\lib\ruby\gems\bcrypt-3.1.10-x86-mingw32\ext\mri> ruby 
extconf.rb
C:\<Ruby Path>\lib\ruby\gems\bcrypt-3.1.10-x86-mingw32\ext\mri> make
generating bcrypt_ext-i386-mingw32.def
compiling bcrypt_ext.c
compiling crypt.c
compiling crypt_blowfish.c
compiling crypt_gensalt.c
compiling wrapper.c
linking shared-object bcrypt_ext.so

(if make is not recognized as a valid command, execute this command and do a 
make again
C:\<Current Folder> C:\<DevKit Path>\devkitvars.bat
Adding the DevKit to PATH...)

C:\<Ruby Path>\lib\ruby\gems\bcrypt-3.1.10-x86-mingw32\ext\mri> make install
/usr/bin/install -c -m 0755 bcrypt_ext.so /C/<Ruby 
Path>/lib/ruby/site_ruby/2.2.0/i386-msvcrt

重新启动您的服务器。

它应该可以解决问题!

于 2016-01-13T19:37:46.833 回答
0

阅读GitHub 上的问题#72#102116 !


更新你Gemfile!将此添加到您的Gemfile

gem 'bcrypt', '3.1.9'

注意!bcrypt-ruby宝石已将其名称更改为bcrypt. 而不是 安装bcrypt-ruby,你应该安装bcrypt。请相应地更新您的依赖项。


然后在 CMD 中运行命令:

bundle

或者

bundle install

该错误已在 3.1.9 版本中修复。不要使用旧版本的 bcrypt!

于 2015-12-13T14:28:35.177 回答