Xenedra
Xenedra

Reputation: 69

Rails server says it cannot load the bcrypt gem?

When I try to do this action I get the "LoadError (cannot load such file -- 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

User model:

class User < ApplicationRecord
has_secure_password
end

I have tried all of the following in the gemfile and I get the same error every time:

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

How can I get it to load the bcrypt gem? I'm using Windows 10.

Upvotes: 0

Views: 409

Answers (1)

saga
saga

Reputation: 26

Try this:

  1. Remove bcrypt from your Gemfile.
  2. Uninstall from your system by running gem uninstall bcrypt.
  3. Add gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' to your Gemfile.
  4. Run bundle install.
  5. If you get errors, install Git https://git-scm.com/downloads and retry bundle install.

Source: https://github.com/codahale/bcrypt-ruby/issues/102#issuecomment-284118731

Upvotes: 1

Related Questions