无法加载此文件--bcrypt_ext。

4
我目前在使用Devise for Rails 5.0.1时遇到了bcrypt加密器的故障。在之前的Rails 4.2中,我从未遇到过这个问题。我无法通过Devise注册新用户。下面是我的gemfile和服务器日志信息。
Gemfile.rb
gem 'bcrypt', platforms: :ruby

# Devise
gem 'devise'
gem 'devise_security_extension'

gem 'redis'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'

服务器日志

Started POST "/register" for 127.0.0.1 at 2017-01-12 13:50:05 -0500
Processing by Users::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"bH6n7iWLhPMECDzTVkMyTc9FXtvkGrq5+K4wFs1g8Bxbjq9ShaLJP5gn72SFQlHc01j2ao5JKcv57ClWAzwsmw==", "user"=>{"email"=>"craigcarl@codex.com", "username"=>"codex", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Completed 500 Internal Server Error in 258ms (ActiveRecord: 0.0ms)



LoadError - cannot load such file -- bcrypt_ext:
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  bcrypt-3.1.11-x86 (mingw32) lib/bcrypt.rb:16:in `rescue in <top (required)>'
  bcrypt-3.1.11-x86 (mingw32) lib/bcrypt.rb:12:in `<top (required)>'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  devise (4.2.0) lib/devise/encryptor.rb:1:in `<top (required)>'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  devise (4.2.0) lib/devise/models/database_authenticatable.rb:147:in `password_digest'
  devise (4.2.0) lib/devise/models/database_authenticatable.rb:40:in `password='
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:46:in `public_send'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:39:in `each'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
  activerecord (5.0.1) lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
  activerecord (5.0.1) lib/active_record/core.rb:319:in `initialize'
  activerecord (5.0.1) lib/active_record/inheritance.rb:65:in `new'
  activerecord (5.0.1) lib/active_record/inheritance.rb:65:in `new'
  devise (4.2.0) lib/devise/models/registerable.rb:20:in `new_with_session'
  devise (4.2.0) app/controllers/devise/registrations_controller.rb:100:in `build_resource'
  devise (4.2.0) app/controllers/devise/registrations_controller.rb:15:in `create'
  actionpack (5.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.0.1) lib/abstract_controller/base.rb:188:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.0.1) lib/active_support/callbacks.rb:126:in `call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
  activesupport (5.0.1) lib/active_support/callbacks.rb:455:in `call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
  activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
  activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (5.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.0.1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
  activerecord (5.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (5.0.1) lib/abstract_controller/base.rb:126:in `process'
  actionview (5.0.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.0.1) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (5.0.1) lib/action_controller/metal.rb:262:in `dispatch'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
  actionpack (5.0.1) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
  actionpack (5.0.1) lib/action_dispatch/routing/mapper.rb:46:in `serve'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
  rack (2.0.1) lib/rack/deflater.rb:35:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (2.0.1) lib/rack/etag.rb:25:in `call'
  rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
  rack (2.0.1) lib/rack/head.rb:12:in `call'
  rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
  rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.0.1) lib/active_record/migration.rb:553:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
  web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
  railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
  sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.1) lib/rack/method_override.rb:22:in `call'
  rack (2.0.1) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
  rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
  railties (5.0.1) lib/rails/engine.rb:522:in `call'
  puma (3.6.2) lib/puma/configuration.rb:225:in `call'
  puma (3.6.2) lib/puma/server.rb:578:in `handle_request'
  puma (3.6.2) lib/puma/server.rb:415:in `process_client'
  puma (3.6.2) lib/puma/server.rb:275:in `block in run'
  puma (3.6.2) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

Started POST "/__better_errors/4e4442c3f810d7b9/variables" for 127.0.0.1 at 2017-01-12 13:50:06 -0500

你使用的 Ruby 版本是什么? - spickermann
这个项目使用的是 Ruby 2.3.1。 - valcod3r
5个回答

11

今天我遇到了一个类似的问题,使用的是ruby 2.3.3和rails 4.2.4。

问题在于devise的bundle install安装了bcrypt的另一个版本(bcrypt (3.1.11 x86-mingw32)而不是bcrypt (3.1.11)),这导致了与ruby 2.3的兼容性问题(它应该可以在之前的所有ruby版本中工作)。

我解决问题的方法是在gemfile之外安装bcrypt,运行bundle然后删除第二个版本的bcrypt:

$ gem list bcrypt
bcrypt (3.1.11 x86-mingw32)

$ gem uninstall devise && gem uninstall bcrypt
Successfully uninstalled devise-4.2.0
Successfully uninstalled bcrypt-3.1.11-x86-mingw32

$ gem install bcrypt --platform=Ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed bcrypt-3.1.11
Parsing documentation for bcrypt-3.1.11
Installing ri documentation for bcrypt-3.1.11
Done installing documentation for bcrypt after 1 seconds
1 gem installed

$ gem list bcrypt
bcrypt (3.1.11)

$ bundle install
...
Installing bcrypt 3.1.11 (x86-mingw32)
...
Installing devise 4.2.0
Bundle complete! 25 Gemfile dependencies, 75 gems now installed.

$ gem list bcrypt
bcrypt (3.1.11 ruby x86-mingw32)

$ gem uninstall bcrypt
Select gem to uninstall:
 1. bcrypt-3.1.11
 2. bcrypt-3.1.11-x86-mingw32
 3. All versions
> 2
Successfully uninstalled bcrypt-3.1.11-x86-mingw32

$ gem list bcrypt
bcrypt (3.1.11)

如果您还没有解决问题,希望这能有所帮助。


5

我也遇到了同样的问题,然后我找到了一些参考资料,发现这只与版本有关。

当我将bcrypt回退到

bcrypt 3.1.0-x86-mingw32

来自

bcrypt 3.1.11-x86-mingw32(the latest now)

请再次确认Gemfile文件中的内容。
gem 'bcrypt-ruby', '3.1.0', :require => 'bcrypt'

然后它就可以正常工作了。

2

我也遇到了这个问题,我的ruby版本是'2.3.3',rails版本是'5.2.0',但目前唯一的解决方案是运行以下命令:

gem uninstall bcrypt
gem install bcrypt --platform=ruby

临时解决方案。


0
也许只是本地的二进制文件构建错误或已损坏。请尝试以下步骤:
  1. 打开命令控制台
  2. cd到gem目录C:\RailsInstaller\Ruby2.2.0\lib\ruby\gems\2.2.0\gems\bcrypt-3.1.10-x86-mingw32\ext\mri
  3. 运行ruby extconf.rb,它应该会创建Makefile文件
  4. 运行make,这将构建扩展库
  5. 运行make install

更多信息请参见修复问题"无法加载文件-- bcrypt_ext(LoadError)"


0

以下是解决MS Win 10和8问题的步骤

  1. 卸载所有的bcrypt

    gem uninstall bcrypt
    
  2. 进入lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/目录,复制bcrypt_ext.so文件,并将其暂时粘贴到桌面上。

  3. 再次卸载所有的bcrypt

    gem uninstall bcrypt 
    
  4. 在项目的Gemfile中添加以下内容

    gem 'bcrypt', '~> 3.1.7'
    
  5. 运行以下命令

    bundle install
    bundle update
    
  6. 将从桌面复制的bcrypt_ext.so文件粘贴到lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/目录下。

  7. 重启服务器

    rails server
    

它可以在Win 7和10上运行!!!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接