Bcrypt gem in Ruby on Rails - ruby-on-rails

I've just created a fresh Rails 5 application. I don't have any MVC's generated yet inside my application.
I added some gems to the gem file including gem 'bcrypt', '3.1.11'.
When I try to create a controller with the rails generator, I get an error.
This is the command with the error that I got:
command>rails generate controller StaticPages home help
C:/Ruby23/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/bcrypt.rb:16:in `require': cannot load such file -- bcrypt_ext (LoadError)
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/bcrypt.rb:16:in `rescue in <top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/bcrypt.rb:12:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `each'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `block in require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `each'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler.rb:106:in `require'
from C:/Users/Doesha/Desktop/rails17/rails_sample_app/config/application.rb:7:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:156:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:156:in `require_application_and_environment!'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:143:in `generate_or_destroy'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:60:in `generate'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
All I did was add gems to my gemfile, so I'm not sure why the rails generator isn't working.
I did notice that my generator stops working when I add the gem bcrypt.
Can someone tell me the reason I can't use my generator once I installed gem 'bcrypt', '3.1.11'?

delete gem 'bcrypt', '3.1.11' from gem file and
use
$gem install bcrypt

Related

cannot load such file -- bcrypt_ext (LoadError) on windows

I have ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32] and rails 5.1.4. I am getting following error when i run rails s command.
rails s
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require': cannot load such file -- bcrypt_ext (LoadError)
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:16:in `rescue in <top (required)>'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x64-mingw32/lib/bcrypt.rb:12:in `<top (required)>'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:83:in `require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:83:in `block (2 levels) in require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:78:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:78:in `block in require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:67:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler/runtime.rb:67:in `require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bundler-1.16.0.pre.2/lib/bundler.rb:114:in `require'
from E:/Rauf Personal Data/work/rails/shine/config/application.rb:7:in `<top (required)>'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `require'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:133:in `block in perform'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I have almost tried every solution but i am unable to resolve this issue. Can any body please help me to sort out this issue. I already tried following:
Firstly uninstall bcrypt and bcrypt-ruby by running these two commands:
gem uninstall bcrypt and gem uninstall bcrypt-ruby
Install it again with gem install bcrypt --platform=ruby
In your Gemfile write gem 'bcrypt-ruby', '3.1.5', :require => 'bcrypt'
Run bundle install
I have managed to solve this issue by adding following line in the Gemfile....
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
After trying several methods, the above worked for me:
1) Stop all rails servers.
2) Add : gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' to the gemfile.
3) bundle install.

rails g mongoid:config error

I get this error when ever I run this command rails g mongoid:config. Does anybody have any idea
/home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/history.rb:1:in `require': cannot load such file -- readline (LoadError)
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/history.rb:1:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/interface.rb:1:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/interface.rb:1:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/core.rb:5:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug/core.rb:5:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug.rb:1:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/byebug-3.5.1/lib/byebug.rb:1:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:76:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:72:in `each'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:72:in `block in require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:61:in `each'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/runtime.rb:61:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler.rb:134:in `require'
from /home/gardezi/blog/config/application.rb:7:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:82:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:82:in `preload'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:143:in `serve'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:131:in `block in run'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `loop'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `run'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/gardezi/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
The commands that I ran are as followed below:
gem install mongoid
rails new blog
gedit /blog/Gemfile
in which I wrote
gem 'mongoid', '4.0.2'
gem 'bson_ext'
and then I ran bundle
and then rails g mongoid:config
Thanks to Shweta the rails g command is not giving an error now but now I am encountering another problem and that is when ever I run this command it's running in infinite loop. It's been seven hours and still running so please tell me what should I do.
THANKS IN ADVANCE
I solved the problem. I just needed to stop the spring.
Follow following steps:
1] Skip active-record while creating new project
rails new blog -O
2] open Gemfile add gem 'mongoid'. No need to add gem 'bson_ext'
gem 'mongoid'
3] Install bundle
bundle install
4] Generate mongoid config file
rails g mongoid:config
Hope this helps.

Unable to generate rspec in rails project, "uninitialized constant RSpec (NameError) is thrown"

>: rails generate rspec:install
/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb:1:in `<top (required)>': uninitialized constant RSpec (NameError)
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec/formatter.rb:1:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec/formatter.rb:1:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec.rb:3:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/allure-rspec-0.6.7/lib/allure-rspec.rb:3:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481#global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /Users/prashanth_sams/Desktop/MAC/blog/config/application.rb:7:in `<top (required)>'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.16/lib/rails/commands.rb:24:in `require'
from /Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.16/lib/rails/commands.rb:24:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I tried the below cmd in Terminal
bundle exec rails generate rspec:install
but no luck :(
Placed the below in my Gemfile
group :test, :development do
gem 'rspec-rails', '~> 3.1.0'
end
May be the version of Rspec is incompatible: downgrade the version of rspec or just write:
gem 'rspec-rails'
then you can update it:
bundle update rspec-rails
I am able to create the spec folder and spec_helper.rb using
rspec --init

Rails 4.1.0 and authlogic bcrypt issue

I'm running the latest OSX with rvm ruby 2.1.0. After bundle update to Rails 4.1.0 and authlogic 3.4.1, when I start the server I get this error:
authlogic/crypto_providers/bcrypt.rb:1:in `require': cannot load such file -- bcrypt (LoadError)
authlogic-3.4.1/lib/authlogic/crypto_providers/bcrypt.rb:1:in `<top (required)>'
authlogic-3.4.1/lib/authlogic.rb:60:in `require'
authlogic-3.4.1/lib/authlogic.rb:60:in `block in <top (required)>'
authlogic-3.4.1/lib/authlogic.rb:59:in `each'
authlogic-3.4.1/lib/authlogic.rb:59:in `<top (required)>'
bundler-1.5.2/lib/bundler/runtime.rb:76:in `require'
bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require'
bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
bundler-1.5.2/lib/bundler.rb:131:in `require'
application.rb:7:in `<top (required)>'
railties-4.1.0/lib/rails/commands/commands_tasks.rb:79:in `require'
railties-4.1.0/lib/rails/commands/commands_tasks.rb:79:in `block in server'
railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `tap'
railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `server'
railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
From this issue on the authlogic github account
Authlogic has changed its default encryption system from SHA512 to SCrypt.
It seems that you need this in your gemfile
gem 'authlogic', '~> 3.4.0'
gem 'scrypt'
If you don't want SCrypt you can use Sha512 by putting this
acts_as_authentic do |c|
c.crypto_provider = Authlogic::CryptoProviders::Sha512
end
in your User.rb
You also might need to specify the version of the authlogic gem
gem 'authlogic', github: 'binarylogic/authlogic', ref: 'e4b2990d6282f3f7b50249b4f639631aef68b939'
but I guess this will be fixed soon

deprecated_mass_assignment_security.rb:14:in `attr_accessible' [voting gem][rails 4]

So, when running
[leap_staging]$rails g reputation_system
After including the gem 'activerecord-reputation-system', require: 'reputation_system' in my Gemfile I get the below error:
/usr/local/rvm/gems/ruby-2.0.0-p195/gems/activemodel-4.0.0/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:25:in `<class:Evaluation>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:18:in `<module:ReputationSystem>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system/models/evaluation.rb:17:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/activerecord-reputation-system-2.0.2/lib/reputation_system.rb:25:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195#global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /Users/apane/Downloads/leap_staging/leap_staging/config/application.rb:7:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands.rb:44:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It's clear to me that this had to with Rails 4 and the new Strong Params. However, I'd like to get this workin'. So, how can I get this to work or convert it to strong_params if I can't even generate the files?
See the full app here if necessary for easy troubleshooting: www.github.com/apane/leap (gem not included)
Have you tried adding the protected_attributes Gem into your Gemfile like the message says?
activerecord-reputation-system gem now supports Rails 4 (since version 3.0).

Resources