LoadError in Devise (無法載入 bcrypt)



所以我在使用Devise创建用户时遇到了问题。这是"bcrypt"的问题。

这是生成的错误

我在这里查看了一些类似的线程,解决方案是为 Ruby 安装 bcrypt gem。所以我去了 rubygems.org 并在 gem 文件中添加了该行,然后运行捆绑安装。

但是,在那之后我尝试运行服务器,但由于某种原因它失败了。服务器无法启动。这是我在 GitBash 中收到的错误:

Zak@ZAKARIA ~/Desktop/Work/raddit (add_users)
$ rails s
c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependen
cies.rb:293:in `require': cannot load such file -- bcrypt_ext (LoadError)
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_sup
port/dependencies.rb:293:in `block in require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_sup
port/dependencies.rb:259:in `load_dependency'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.2/lib/active_sup
port/dependencies.rb:293:in `require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/bcry
pt.rb:16:in `rescue in <top (required)>'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/bcry
pt.rb:12:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:91:in `require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:91:in `block (2 levels) in require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:86:in `each'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:86:in `block in require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:75:in `each'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler/runtime
.rb:75:in `require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.7/lib/bundler.rb:106:
in `require'
        from c:/Users/Zak/Desktop/Work/raddit/config/application.rb:7:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/
commands_tasks.rb:88:in `require'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/
commands_tasks.rb:88:in `block in server'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/
commands_tasks.rb:85:in `tap'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/
commands_tasks.rb:85:in `server'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands/
commands_tasks.rb:49:in `run_command!'
        from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.2/lib/rails/commands.
rb:18:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

注意:在添加 gem 之前,服务器将正常运行。

这里也是我的宝石文件

gem 'rails', '~> 5.0.2'
gem 'sqlite3'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'devise', '~> 4.2', '>= 4.2.1'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1', '>= 3.1.11'
group :development, :test do
   gem 'byebug', platform: :mri
end
group :development do
  gem 'web-console', '>= 3.3.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
我认为

您不需要在 Gemfile 中设置显式 bcrypt。Devise已经将bcrypt作为运行时依赖项包含在内。尝试从 Gemfile 中删除 bcrypt gem,运行 bundle update 并重新启动服务器。这对我有用。

基于 ajeferson 的 asnwer。

此线程具有解决方案:github.com/codahale/bcrypt-ruby/issues/142

我遇到了同样的问题,对我来说,每当我运行捆绑安装时,它都会安装两个版本的 bcrypt:

  1. bcrypt-3.1.11
  2. bcrypt-3.1.11-x86-mingw32

因此,如果我只是执行">gem 卸载 bcrypt"并删除 (2(,那么它工作正常。

为了确保它不会再次安装,我在 Gemfile 上指定了平台,如下所示:

gem 'bcrypt', platform: :ruby

最新更新