ruby在轨道上,运行服务器不工作,因为bcrypt_ext(LoadError)

我从https://github.com/mhartl/rails_tutorial_3rd_edition_gemfiles/blob/master/sample_app/Gemfile得到了gem

那么我会收到类似的错误消息

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>' 

这个问题是特定于Windows,在bcrypt-ruby问题:72中解决 。

更新你的Gemfile为:

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

然后

 bundle install 

只要按照这个链接的步骤:这工作对我来说https://www.ambidev.com/loaderror-cannot-load-such-file-bcrypt_ext/

你应该已经正确安装并配置了DevKit来重新编译gem。

 LoadError: cannot load such file -- bcrypt_ext 

Firt停止你的服务器,并删除所有的bcrypt宝石或bcrypt-ruby宝石。

 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中包含bcrypt gem'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 

重新启动您的服务器。

它应该做的伎俩!

阅读GitHub上的问题#72 , #102和116 !


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

 gem 'bcrypt', '3.1.9' 

注意!bcrypt-ruby宝石已经改名为bcrypt 。 而不是安装bcrypt-ruby ,你应该安装bcrypt 。 请相应地更新您的依赖关系。


然后在您的CMD中运行命令:

 bundle 

要么

 bundle install 

该bug在版本3.1.9中被修复。 不要使用旧版本的bcrypt!