简体   繁体   English

Devise中的LoadError(无法加载bcrypt)

[英]LoadError in Devise (Cannot load bcrypt)

So I'm having issues with creating users with Devise. 因此,在使用Devise创建用户时遇到了问题。 It's an issue with "bcrypt". 这是“ bcrypt”的问题。

Here is the error that's being generated 这是正在生成的错误

I looked at a few similar threads here and the solution was to install the bcrypt gem for Ruby. 我在这里查看了一些类似的线程,解决方案是为Ruby安装bcrypt gem。 And so I went to rubygems.org and added the line in gem file then ran bundle install. 因此,我去了rubygems.org并在gem文件中添加了该行,然后运行了bundle install。

However, after that I try to run the server but it fails for some reason. 但是,在那之后,我尝试运行服务器,但是由于某种原因它失败了。 Server won't start. 服务器无法启动。 Here is the error I received in GitBash: 这是我在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>'

NOTE: Before adding the gem, the server would run just fine. 注意:在添加gem之前,服务器可以正常运行。

Also here is my gem file 这也是我的宝石文件

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]

I don't think you need to set the explicitly bcrypt in your Gemfile. 我认为您无需在Gemfile中设置显式bcrypt。 Devise already includes bcrypt as a runtime dependency. Devise已将bcrypt包含为运行时依赖项。 Try to remove the bcrypt gem from your Gemfile, run bundle update and the restart your server. 尝试从Gemfile中删除bcrypt gem,运行bundle update并重新启动服务器。 That worked for me. 那对我有用。

Based on ajeferson's asnwer. 基于ajeferson的回答。

This thread has the solution: github.com/codahale/bcrypt-ruby/issues/142 该线程具有解决方案:github.com/codahale/bcrypt-ruby/issues/142

I had the same issue, and for me, whenever I run bundle install, it installs two versions of bcrypt: 我遇到了同样的问题,对我来说,每当我运行捆绑安装时,它都会安装两个版本的bcrypt:

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

Therefore, If I just executed " gem uninstall bcrypt " and deleted the (2), then it worked fine. 因此,如果我只是执行“ gem uninstall bcrypt ”并删除了(2),那么它可以正常工作。

To make sure it will not be installed again, I specify the platform on my Gemfile, like this: 为了确保不会再次安装,我在Gemfile上指定平台,如下所示:

gem 'bcrypt', platform: :ruby

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM