I'm beginner in Ruby on Rails and trying to learn from http://ruby.railstutorial.org/ I'm creating sample_app and got stuck at chapter 6.
My Ruby version: ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
My Rails version: Rails 4.0.0
I have following line in my GemFile:
gem 'bcrypt-ruby', '~> 3.0.0'
If I type gem list bcrypt-ruby , it shows bcrypt-ruby (3.0.1) . But if I try to create user, I get error saying
You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install
I searched a lot on rails website, bcrypt website & even stackoverflow. But, nothing worked. Please help.
I've faced this issue recently (as have many others). As per ladyruby723 posted here, use gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' in your gemfile file.
I solved this the same problem by the following line:
gem 'bcrypt-ruby', '~> 3.1.2'
I believe this exact issue is solved in another question. There are actually two error messages produced, this being the higher level one, by searching for the lower level I found the below answer.
can't activate bcrypt-ruby (~> 3.0.0), already activated bcrypt-ruby-3.1.1. Make sure all dependencies are added to Gemfile
add below in gem file
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
and run bundle install and restart server
Finally... Got it working. I didn't understand the exact issue but I made two important changes. I'm not sure which change made it working.
I uninstalled my old ruby & rails that were installed from railsinstaller. Installed just ruby for my OS (64 bit which I was not able to choose while installing from railsinstaller). Then I installed rails, sqlite3 separately.
Another important change I did is in Gemfile.lock. I think this did the trick. I kept both of the following lines
bcrypt-ruby (3.0.0)
bcrypt-ruby (3.0.0-x86-mingw32)
In my case, the problem was that bcrypt version 3.1.2 was outdated. Fortunately Ruby has a way of installing the most up to date version of a particular gem right from your command line. In this case I typed in
bundle pristine bcrypt
but more generally you can do
bundle pristine gem name
If you think you might be running into a similar issue with a different gem
Related
I'm trying to install the pg_search gem. In the first attempt I did not pay attention to the necessary version of ruby (we are using 2.3.1 and 2.4 was required), in the error message that appeared I was asked to run bundle update, but it updated pg_search to 2.3.5 which require ruby >= 2.5. Even though I specified an older version of the gem, it still shows the same message:
Gem::InstallError: pg_search requires Ruby version >= 2.5.
An error occurred while installing pg_search (2.3.5), and Bundler cannot continue.
Make sure that `gem install pg_search -v '2.3.5'` succeeds before bundling.
I already installed the gem by running docker-compose run web gem install pg_search -v 2.1.4, and recreated the container. My Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 5.2.0'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
#gem 'mina-puma', :require => false
gem 'puma', '~> 3.7.1'
gem 'pg', '~> 0.18'
gem 'pg_search', '~> 2.1', '>= 2.1.4'
...
Bundler version: bundler (>= 1.3.0)
I would like to know how to remove pg_search 2.3.5 and install 2.1.4.
Even though I specified an older version of the gem
No, you didn't.
You specified '~> 2.1', '>= 2.1.4', which means anything 2.1.4 <= version < 3.0.0.
By running bundle update, this installed the latest available version that met your requirements, which was apparently 2.3.5, not 2.1.4.
If you need to also specify a constraint to ruby version 2.3.1, you can also put this in the Gemfile:
ruby '2.3.1'
...And then running bundle update will also take that into consideration when finding the latest compatible dependencies.
I would like to know how to remove pg_search 2.3.5 and install 2.1.4
You don't have version 2.3.5 installed against this ruby version, because it's incompatible.
Apparently you've already installed version 2.1.4.
The problem is that your Gemfile.lock is still expecting version 2.3.5. There are a few ways you could resolve this, but one way or another you need to update the Gemfile.lock to have a compatible set of dependencies with your ruby version.
The simplest approach is probably to just re-run bundle update pg_search, but make sure you're actually using the correct ruby version this time. That should downgrade the dependency, as the newer library version isn't compatible with the older ruby version.
If you still encounter issues, you could take my advice of adding the ruby constraint to the Gemfile, and revert whatever other changes you've recently made that created this incompatible mix of dependencies.
I am using rails 4.2.1. I have already added rails_admin module in my app. Now, I want to add email facility for admin, so that he can send email to the users. For that, I have added rails_admin_email gem.
But when I execute bundle install command some dependency issues occur
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 4.2.1)
rails_admin_email was resolved to 0.0.1, which depends on
rails (~> 3.2.6)
How can I solve the issue?
Please also provide some useful hint, if there is a better way than using rails_admin_email gem
Here are my current GemFile and Gemfile.lock .
While this answer should fix the problem i would not encourage you to use rails_admin_email as it has not been touched since July 2012 and not present on rubygems.org :). Still solution below.
The problem in this case is the dependencies defined
rails_admin_email for rails is s.add_dependency "rails", "~> 3.2.6"
rails_admin for rails is s.add_dependency 'rails', ['>= 4.0', '< 6']
To fix this problem you need to fork/pr rails_admin_gem to use >= 3.2.6. Here is what i tried in my fork and it works.
I keep getting this error when i try to run my app:
C:/ruby-2.0.0-p195-i386-mingw32/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0.rc1
/lib/active_support/dependencies.rb:228:in `require': cannot load such file -- 2
.0/bcrypt_ext (LoadError)
Any takers? - im trying to use the devise gem for basic user authentication..
I've gotten this error when I updated to Ruby 2.0.0+ on Windows. I was able to solve it by uninstalling all versions of bcrypt that were downloaded, and building the gem using DevKit.
gem uninstall bcrypt-ruby
gem install bcrypt-ruby --platform=ruby --no-ri --no-rdoc
Usually doing a bundle update will download a precompiled gem mingw32 extension, which in this case appears not to work. This workaround for reinstalling bcrypt-ruby will hopefully not be needed in the future.
Additionally, I keep updated Windows installation instructions for Ruby on Rails here (mostly for my own reference) for installing Ruby on Rails on Windows.
https://github.com/remomueller/documentation/tree/master/windows
Some other Windows pitfalls you may run into are also listed there:
https://github.com/remomueller/documentation/blob/master/windows/190-miscellaneous.md
Until this problem is fixed, the best workaround is to install bcrypt-ruby from git:
gem 'bcrypt-ruby', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
Update (June 2016.) - as #gneri mentioned, bcrypt-ruby changed it's name to bcrypt, so use:
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
On problem with has_secure_password on Window 7 helps this
gem uninstall bcrypt-ruby
gem uninstall bcrypt
gem install bcrypt-ruby --platform=ruby --no-ri --no-rdoc
gem install bcrypt --platform=ruby --no-ri --no-rdoc
Add to Gemfile:
gem 'bcrypt-ruby', '~> 3.0.0', :require => 'bcrypt'
gem 'bcrypt'
bundle install
turns out that it was a problem with the version of ruby that i was using. I was using ruby 2 (32bit).
but if you switch to the 64bit version of ruby 2 the error goes away.
Seems like the downfall of using windows as a development platform for ROR apps. I need to use Ruby 2.0 32 bit in order to get PG gem for a postgresql connection to work or I have to use Ruby 2.0 64 bit to get 'Devise' gem to work.
The new version of bundler just came out. It nows about x64 gems
gem install bundler -v '1.4.0.pre.2'
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?
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
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.
In your Gemfile add a line
gem 'bcrypt-ruby'
and then from the command line
bundle install
Something that came up for me that is not addressed here yet. I got this error after going to a new system on which I installed Ruby 2.0.x.
It turns out that even if I was using the new bcrypt 3.1.7 it didn't work for me until I ALSO had bcrypt-ruby 3.0.1 in the gemfile. I resisted that when I should have just taken the error at it's word.
gems:
bcrypt (3.1.7 ruby x86-mingw32)
bcrypt-ruby (3.0.1 x86-mingw32, 3.0.0)
gemfile:
gem 'bcrypt-ruby', '~> 3.0.1'
gem 'bcrypt', '~> 3.1.7'
Before adding both I tried all sorts of single version combinations.
Restart the server and reinstall bundle in correct order, that is:
bundle install, bundle update, bundle install
and then server restart.
If you already put the gem in the gem file and bundle installed and you are still getting an error then restart your server.
While trying to install Rails admin, I added it to my gem file as instructed. I deleted the gemfile.lock
Then I ran bundle install. I got this message:
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails_admin depends on
rails (~> 3.0.3)
rails (3.0.1)
I am using rails 3.0.1, not really sure I understand the issue? But its obviously stopping me from installing.
Also, if I put rails_admin in the gem file like so:
gem 'rails_admin'
instead of:
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
that seems to install it a version 0.0.0 and then doesn't proceed to do anything (so clearly thats not right either).
Is there a version I can specify that might work?
Thanks!
The issue is that the gem now required rails 3.0.3 and you are using 3.0.1
~> means at least this tiny revision or greater.
E.G. ~> 3.0.3 means 3.0.x where x >= 3
As for what gem version will work on 3.0.1 I do not know.