当我尝试执行此操作时,我得到" 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。
答案 0 :(得分:1)
试试这个:
bcrypt
。gem uninstall bcrypt
。gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
添加到您的Gemfile。bundle install
。bundle install
。来源:https://github.com/codahale/bcrypt-ruby/issues/102#issuecomment-284118731