how to know mongoid gem version? - ruby-on-rails

I am new to ruby on rails and am trying to run my first application which connected to MongoDb. How do i know if I have Mongoid gem installed or if I have to install it? and what is the command to know the gem version.
In my rails application Gemfile I have added:
gem 'mongoid', '~> 5.0.0'
but it gives the error:
usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/resolver.rb:366:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'mongoid (~> 5.0.0.1)' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)

I think the gem is not present in your local machine. So it's giving you error. Try running command
bundle install
or you can manually install this gem using console by this command
gem install mongoid -v 5.0.0
Hope it helps. Cheers!

Related

Globalid and pg not existing when in gemfile

I am trying to rails server from a cloned repo, I have updated ruby, and rails, followed the rvm process, updated all my gem files, and when I go to serve I receive the message
Could not find globalid-0.3.7 in any of the sources Run bundle
install to install missing gems.
So I do bundle install, then get the error
An error occurred while installing pg (0.20.0), and Bundler cannot
continue. Make sure that gem install pg -v '0.20.0' succeeds before
bundling.
Try to insall that and then get
ERROR: Could not find a valid gem 'globalid-0.3.7' (>= 0) in any
repository ERROR: Possible alternatives: globalid, globalize3
I have googled everything and asked many.
globalid is a dependency of the Rails core gem ActiveJob so it is a required gem to have in your Gemfile.lock. See if it is listed in your Gemfile.lock file. If not you could add it to the top of your gemfile including the version
# gemfile
gem 'globalid', '0.3.7'
Then bundle install. If it works, then you can delete it from your gemfile since it should load automatically when Rails loads (since it is a dependency of Rails' ActiveJob). I've run into a similar issue with another gem and this process worked for me.
It could be a version error. Try using gem 'globalid', '~> 0.4.0' in your gemfile and bundling.

Cannot install gem march_hare

I tried adding this to my Gemfile:
gem 'march_hare', '~> 2.22'
Using bundle install I got this message:
Could not find gem 'march_hare (~> 2.22)' in any of the gem sources listed in
your Gemfile or available on this machine.
On the topmost line in my Gemfile, I have this :
source 'https://rubygems.org'
When I manually visit the rubygems and I m able to find this gem here :
https://rubygems.org/gems/march_hare
How do I install this gem? I don't understand what is happening.
It doesn't work with any jRuby older than 9.0, this was a miss on my part

Gem::LoadError for mysql2 gem, but it's already in Gemfile

Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded.
Add `gem 'mysql2'` to your Gemfile
This error occurred while loading the following files:
active_record/base
This is the error I get on running rails server.
The mysql2 gem has been added to the Gemfile as well.
I've done bundle install, and tried restarting the server but still get the error.
If you have this error when upgrading to rails 4.2.4 (also with rails 4.1.5) try using this version of mysql2:
gem 'mysql2', '~> 0.3.18'
Apparently mysql2 isn't still compatible with newer version of rails because rails 4.2.4 is pretty new as the time of answering this question by me 8 September 2015 so use the above line in your Gem file and run:
bundle install
You should be good to go
It worked for me when I specified a mysql2 gem version before the newest one (0.4.0).
For some reason there is a problem with Rails 4.2.4 and that gem 0.4.0. So, to solve the problem I just specified the previous gem released: 0.3.20 and it worked fine for me!
gem 'mysql2', '~> 0.3.20'
bundle install
You can check all the gems versions here: https://rubygems.org/gems/mysql2/versions
Change to
gem 'mysql2', '~> 0.3.18'
in your Gemfile.
This thread on the official mysql2 Github says to do this. You need to declare that version number if you're rails version 4.x.x.
https://github.com/brianmario/mysql2/issues/675
Then run bundle update mysql2.
I got the same error after an upgrade to Rails 4.1 and I managed to resolve it by updating mysql2. Run this in your rails app folder:
$ bundle update mysql2
This issue may occur if you're using newer version of rails > 4
Do these two simple steps, it will work.
Open your Gemfile and find the below line
gem 'mysql2'
replace that line with a specific mysql version like below
gem 'mysql2', '~> 0.3.18'
Now stop the server and run bundle
bundle install
Now restart your server. It should work.
rails s
Being Beginner to the ruby i could not figure out the line
gem 'mysql2', '~> 0.3.18'
it simply means go to your rails project folder and then there is
line for mysql2 it will be like 0.4* so you can change it to
gem 'mysql2', '~> 0.3.18'
and as we have new definition, we have to rebuild the dependency so to do that simple command as explained on the top bundle install
It doesn't load mysql2 gem because new version of mysql2(0.4.1) gem unable to load the mysql2_adaptor. This is working for me.
gem 'mysql2', '~> 0.3.13'
and run
bundle install
I had the same error and this is because Rails 4.1 requires minimum mysql2 version 0.3.13, and maximum compatible with Windows is version 0.3.11.
So I edited file c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\activerecord-4.1.1\lib\active_record\connection_adapters\mysql2_adapter.rb and changed line gem 'mysql2', '~> 0.3.13' to gem 'mysql2', '~> 0.3.11', and it works so far.
Here is how I fixed this:
bundle config
bundle config --delete without
bundle install --deployment --without development test postgres
Credits:
How do you undo bundle install --without
It doesn't load mysql2 gem because new version of mysql2 (>= 0.4.0) gem unable to load the mysql2_adaptor. Can you try this?
gem 'mysql2', '~> 0.3.13'
Hopefully, it should work.
I solved the problem, installing the mysql2 gem local (gem install mysql2, bundle install) and adding the following line to the Gemfile:
gem 'mysql2'
Setting the mysql2 adapter in database.yml
adapter: mysql2
was also important!
I'm brand spanking new to Ruby on Rails and websites but hears what worked for me.
I had to change my gemfile, gem 'mysql2' to gem 'mysql2', '~> 0.3.13'
then in rails i typed bundle install
then i tried rails s and got errors
so then i tried bundle update mysql2
then in rails typed rails s, and it worked
I solved the problem, installing the libmysqlclient-dev.
sudo aptitude install libmysqlclient-dev
and later run bundle.
I have previously installed mysql2 0.4.5 but that was giving me this error so i have installed another version of mysql2 by:
gem install mysql2 --version 0.3.20
Hope this solves your problem.

bcrypt error: Devise ruby 2.0 and rails 4.0

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'

Error stating that "bcrypt-ruby is not part of the bundle", how can I add bcrypt-ruby to Gemfile?

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.

Resources