Rails has_secure_password cannot load such file — bcrypt

淺唱寂寞╮ 提交于 2019-12-11 16:50:19

问题



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:

  1. git clone https://github.com/codahale/bcrypt-ruby.gi]t
  2. cd bcrypt-ruby
  3. gem build bcrypt.gemspec
  4. gem install gem-compiler
  5. gem compile bcrypt-3.1.11.gem
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!