Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

Started GET "/users" for 127.0.0.1 at 2012-02-19 16:37:12 +0900

Gem::LoadError (bcrypt-ruby is not part of the bundle. Add it to Gemfile.):
app/models/user.rb:3:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/users_controller.rb:1:in `<top (required)>'

I installed bcrypt-ruby by

$ gem install bcrypt-ruby
Building native extensions.   This could take a while...
1 gem installed
Installing YARD (yri) index for bcrypt-ruby-3.0.1...
Installing RDoc documentation for bcrypt-ruby-3.0.1...

but was no avail.

I tried

$ bundle exec rails server

but was no help.

If I comment out the line "has_secure_password", this error does not come out.

How can I solve this problem?

like image 207
Kichang Yang Avatar asked Feb 19 '12 07:02

Kichang Yang


2 Answers

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
like image 51
user664833 Avatar answered Oct 29 '22 04:10

user664833


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.

like image 44
Frederick Cheung Avatar answered Oct 29 '22 02:10

Frederick Cheung