问题
I'm trying to create simple authentication in Ruby on Rails.
I'm currently stuck, because after creating table in database and adding in model has_secure_password
I'm getting error LoadError: cannot load such file -- bcrypt
.
The error occur when I'm trying in rails console
using basic command: User.all
.
I have looked at many solutions but nothing helped me.
Currently I have installed bcrypt from https://github.com/codahale/bcrypt-ruby.git
but still not working.
Thank you in advance for your help.
回答1:
If you are using Rails 4+, has_secure_password
is not shipped by default anymore, and you will have to include the bcrypt
gem in your Gemfile:
gem 'bcrypt'
Run bundler again:
> bundle install
Then restart your server:
> bundle exec rails s
More info to be found here: http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html
Hope this will help.
回答2:
I don't know why but nothing didn't help me.
Finally I used devise gem instead of doing authentication myself.
Devise gem also using bcrypt but then code below do the job:
- git clone https://github.com/codahale/bcrypt-ruby.gi]t
- cd bcrypt-ruby
- gem build bcrypt.gemspec
- gem install gem-compiler
- gem compile bcrypt-3.1.11.gem
- gem install bcrypt-3.1.11-x86-mingw32.gem --local
Thank you all for trying to help me.
回答3:
On windows 10
I I solved this using this steps
Step 1.
gem uninstall bcrypt
gem uninstall bcrypt-ruby
Step 2
gem install bcrypt --platform=ruby
Step 3
Add to your Gemfile
gem 'bcrypt', platforms: :ruby
devise
If you use devise then not need add bcrypt gem on your gem file follow below steps
gem uninstall bcrypt
gem install bcrypt --platform=ruby
Finally, restart your server
Hope to help
来源:https://stackoverflow.com/questions/48244425/rails-has-secure-password-cannot-load-such-file-bcrypt