Rails错误 - "无法加载此类文件 - bcrypt_ext"在Windows 7,64上

时间:2017-08-07 17:12:48

标签: ruby-on-rails bcrypt

我在Windows 7 64位,我正在运行Ruby 2.3.3和Rails 5.1.2。在尝试在我的网站上创建新用户时,我遇到了我的RoR项目的错误:

  

" Devise中的LoadError :: RegistrationsController #create" "无法加载   这样的文件--bcrypt_ext"

我通过Google搜索找到了这个和类似的解决方案:

  

"首先通过运行这两个来卸载bcrypt和bcrypt-ruby   命令:gem uninstall bcrypt和gem uninstall bcrypt-ruby安装   再次使用gem install bcrypt --platform = ruby​​在你的Gemfile中写一下   gem' bcrypt-ruby',' 3.1.5',:require => ' bcrypt'运行bundle install"

但是,当我尝试在我的控制台中运行gem uninstall bcrypt时,我收到以下错误消息:

  

" $ gem uninstall bcrypt错误:执行gem时......   (宝石:: DependencyRemovalException)       由于依赖gem(s)"

,卸载中止

我相信这是由于我的Devise宝石。当我在控制台中运行gem list bcrypt时,我会收到此输出:

  

" bcrypt(3.1.11 x86-mingw32)"

     

我的rails应用程序附带了我的gem文件中注释掉的这一行:

     

"#使用ActiveModel has_secure_password

     

gem' bcrypt','〜> 3.1.11'"

我已经尝试将其取消注释回代码,当我这样做时,Rails服务器无法加载并在控制台中列出此错误:

C:\Users\James\Desktop\rails_app>rails s
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.1.3/lib/act
ive_support/dependencies.rb:292:in `require': cannot load such file -- bcrypt_ex
t (LoadError)
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-
5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-
5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-
5.1.3/lib/active_support/dependencies.rb:292:in `require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-
x86-mingw32/lib/bcrypt.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/bcrypt.rb:12:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:82:in `require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:77:in `each'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:77:in `block in require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:66:in `each'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler/runtime.rb:66:in `require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.15.2
/lib/bundler.rb:108:in `require'
        from C:/Users/James/Desktop/rails_app/config/application.rb:7:in `<top (
required)>'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/commands/server/server_command.rb:129:in `require'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/commands/server/server_command.rb:129:in `block in perform'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/commands/server/server_command.rb:126:in `tap'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/commands/server/server_command.rb:126:in `perform'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li
b/thor/command.rb:27:in `run'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li
b/thor/invocation.rb:126:in `invoke_command'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.4/li
b/thor.rb:369:in `dispatch'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/command/base.rb:63:in `perform'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/command.rb:44:in `invoke'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.1.3
/lib/rails/commands.rb:16:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

此时,我没有想法。请指教。谢谢。

2 个答案:

答案 0 :(得分:0)

在卸载bcrypt-ruby之前,您应该卸载bcrypt,因为这是依赖的gem。

这可以这样做:

gem uninstall bcrypt-ruby
gem uninstall bcrypt
gem install bcrypt --platform=ruby

答案 1 :(得分:0)

尝试以下适用于我的步骤:

  1. 从您的Gemfile中删除与brypt相关的任何内容
  2. 在Gemfile中输入以下信息
  3. gem'bcrypt',git:'https://github.com/codahale/bcrypt-ruby.git',:require =&gt; 'bcrypt'

    1. 在项目的根目录运行'bundle install',它应该可以正常工作。
    2. 出于某种原因,当你将它指向git页面时,它对我有效。