Rails服务器说它无法加载bcrypt gem?

时间:2017-05-24 19:54:21

标签: ruby-on-rails ruby bcrypt

当我尝试执行此操作时,我得到" LoadError(无法加载此类文件 - bcrypt)"

require 'bcrypt'

class PublicController < ApplicationController

  def attempt_login
        if params[:email].present? && params[:password].present?
            found_user = User.where(:email => params[:email]).first
            if found_user
                authorized_user = found_user.authenticate(params[:password])
            end
        end
        if authorized_user
            render(:text =>'authorized')
            redirect_to(:controller => 'private', :action => 'home')
        else
            flash[:notice] = "Invalid email or password"
            render :new
        end
  end
end

用户模型:

class User < ApplicationRecord
has_secure_password
end

我在gemfile中尝试了以下所有内容,每次都会出现同样的错误:

gem 'bcrypt', '~>3.1.11'
gem 'bcrypt', '~> 3.1', '>= 3.1.11'
gem 'bcrypt', platforms: :ruby

如何才能加载bcrypt gem? 我使用的是Windows 10。

1 个答案:

答案 0 :(得分:1)

试试这个:

  1. 从Gemfile中删除bcrypt
  2. 运行gem uninstall bcrypt
  3. 从系统中卸载
  4. gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'添加到您的Gemfile。
  5. 运行bundle install
  6. 如果您收到错误,请安装Git https://git-scm.com/downloads并重试bundle install
  7. 来源:https://github.com/codahale/bcrypt-ruby/issues/102#issuecomment-284118731