Error stating that “bcrypt-ruby is not part of the bundle”, how can I add bcrypt-ruby to Gemfile?

后端 未结 6 666
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 12:10

When I add has_secure_password to the model (inherited from ActiveRecord::Base), error stating that \"bcrypt-ruby is not part of the bundle\" occurs.

Here the log is

相关标签:
6条回答
  • 2021-01-11 12:39

    As the message says you need to add bcrypt-ruby to your Gemfile (at the root of the project).

    Adding

    gem "bcrypt-ruby"
    

    and then running bundle install should do the trick (this would fetch the gem if you hadn't already installed it).

    You can specify specific versions to, eg

    gem "bcrypt-ruby", "~> 3.0.1"
    

    will get you the latest version that is >= to 3.0.1 but less than 3.1. You might do this if 3.0.1 has a bug fix you depend on and you're happy to get more bug fixes but you don't want major changes. There's loads more info on the bundler website.

    0 讨论(0)
  • 2021-01-11 12:46

    In your Gemfile add a line

    gem 'bcrypt-ruby'
    

    and then from the command line

    bundle install
    
    0 讨论(0)
  • 2021-01-11 12:53

    Restart the server and reinstall bundle in correct order, that is:

    bundle install, bundle update, bundle install
    

    and then server restart.

    0 讨论(0)
  • 2021-01-11 12:53

    If you already put the gem in the gem file and bundle installed and you are still getting an error then restart your server.

    0 讨论(0)
  • 2021-01-11 12:55

    Something that came up for me that is not addressed here yet. I got this error after going to a new system on which I installed Ruby 2.0.x.

    It turns out that even if I was using the new bcrypt 3.1.7 it didn't work for me until I ALSO had bcrypt-ruby 3.0.1 in the gemfile. I resisted that when I should have just taken the error at it's word.

    gems:

    bcrypt (3.1.7 ruby x86-mingw32)
    bcrypt-ruby (3.0.1 x86-mingw32, 3.0.0)
    

    gemfile:

    gem 'bcrypt-ruby', '~> 3.0.1'
    gem 'bcrypt', '~> 3.1.7'
    

    Before adding both I tried all sorts of single version combinations.

    0 讨论(0)
  • 2021-01-11 13:02

    I already had gem 'bcrypt-ruby', '~> 3.0.0' in Gemfile, and had already ran the command bundle, and yet I still got that message. The problem was that I forgot to restart the server:

    touch tmp/restart.txt
    
    0 讨论(0)
提交回复
热议问题