Definitely,
gem install bcrypt-ruby
this will make has_secure_password
work. Also remember to restart the rails server after to see the change.
题
I'm new to Ruby on Rails ans so I'm following the Tutorial Agile Web Development with Rails 4. But on the User Authentification I'm getting an Error which I just can't solve... I've made a Form so the Users can log in and for that I'm using has_secure_password at the file user.rb:
class User < ActiveRecord::Base
has_secure_password
validates :name, presence: true, uniqueness: true
end
but when I run the Server i get the error:
cannot load such file -- 2.0/bcrypt_ext
heres the Application Trace
app/models/user.rb:2:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/users_controller.rb:7:in `index'
This error occurred while loading the following files:
bcrypt
bcrypt_ext
2.0/bcrypt_ext
I have includet gem 'bcrypt-ruby', '~> 3.0.0' in the gemfile but it still don't works.
I've read in similar Questions that it has something to do with "Bundle install" but i can't solve the problem.
Thanks in advance
解决方案
Definitely,
gem install bcrypt-ruby
this will make has_secure_password
work. Also remember to restart the rails server after to see the change.
其他提示
We can only imagine what platform are you using, but I assume *nix derivative.
Editing your Gemfile
is not enough - bundle install
command will do the job for you.
You'll need native compilation toolchain installed also, because bcrypt_ruby
is building some native extensions during installation.
Maybe you are using RVM if so you should install bcrypt gem for the global gemset
:
rvm gemset use global
gem install bcrypt
rvm gemset use whatever_gemset_you_use_previously
(I use bcrypt
instead of bcrypt-ruby
because of the deprecation message for the latter)