Gemfile updated, error doing bundle install - ruby-on-rails

I´m totally lost so i will try to explain my problem.
Actually im reading the book Ruby on Rails tutorial. I´m actually installing all the environment to start learning this language.
The book asks me to update the Gemfile, and add this
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
So i delete my old gem sass-rails, my old gem coffee-rails and my old gem uglifier.
After doing this the book asks me to save it and run Bundle install on my console.
After doing this i get this message:
You have requested:
coffee-rails = 3.2.2
The bundle currently has coffee-rails locked at 4.0.1.
Try running `bundle update coffee-rails`
So i´m totally lost, and i have no idea what i´m doing cause im only following the steps from the book. Someone could help me and tell me what i should do here? Why the book is asking me to do all this if then it does´t work?

Sounds like you have already done a bundle install on a newer (probably without the version requirement) of coffee-rails and that is currently locked down in your Gemfile.lock file.
Do what it says and run bundle update coffee-rails to update your Gemfile.lock file to the version you specify

Related

How to use a specific Nokogiri version for Rails application

I'm trying to run a Rails application that I wrote a couple of years ago, however I keep getting this error when I run rails server:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'nokogiri' (>= 1.5.9) - did find: [nokogiri-1.5.6] (Gem::LoadError)
I'm pretty confused, since I have Nokogiri v1.8.2 and v1.10.7 installed and see them under .gem/ruby/2.3.0 and /Library/Ruby/Gems/2.3.0. I don't see Nokogiri v1.5.6 though, so I'm not sure where the application is getting that from.
I tried adding
gem 'nokogiri', '~> 1.10', '>= 1.10.3'
to the Gemfile, as well as
gem 'nokogiri', '~> 1.5.6'
I'm trying to figure out if I can change the GEM_PATH, but hopefully there's another solution I'm not seeing.
Nokogiri is used by Rails, so you don't need to add it to your Gemfile, but you can update the version in your Gemfile.lock using:
bundle update nokogiri

How can I get bundler to use the tilder operator when the gem version isn't semantic?

As of the writing of this question, the latest sass-rails version is 5.0.0.beta1.
I want to update my Gemfile to use this version but also have it continue to use later releases of sass-rails v5 as and when they become available. For the moment, let's assume that I constantly run bundle update sass-rails and don't care for the consequences to my app.
I find that gem 'sass-rails', '>= 5.0' doesn't work. I get this error:
Could not find gem 'sass-rails (>= 5.0) ruby' in the gems available on this machine.
If I fix the version to =5.0.0.beta1, I get the update just fine.
How can I set an optimistic constraint right now, so that bundle update gives me 5.0.0 when it is released, without my having to change the Gemfile?
You're on the right track but 5.0.0.beta1 is less than 5.0 you'd need your gemfile to have:
gem 'sass-rails', '>= 5.0.0.beta1'
Then it will update when 5.0 becomes available :)

bcrypt-ruby - You don't have bcrypt-ruby installed in your application

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

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.

"Bundle install" fails with "thin", and cannot point a different "eventmachine"

I work with Ruby 1.9.3 on Windows.
**I have a trouble to do "bundle install" due to a "thin" gem, for my app.
My original GEMFILE looks like this:
gem "sinatra"
gem "mogli"
gem "json"
gem "httparty"
gem "thin"
Running "bundle install" causes Installing eventmachine (0.12.10) with native extensions which fails. Error is described here: Cannot install thin on windows
Just to mention that "gem install thin" is successful!
Some people on the net, facing this issue, suggested to install
"eventmachine" version 1.0.0.beta.4.1 which I did:
gem list --local shows eventmachine (1.0.0.beta.4.1 x86-mingw32, 1.0.0.beta.2 x86-mingw32)
Yet "bundle install" fails.
In another post: ROR 3.1: Bundle update fails (eventmachine gem)
I followed the advise to specify the exact version of "eventmachine" in GEMFILE, so I edited it like (hopefully I did it right)
gem "sinatra"
gem "mogli"
gem "json"
gem "httparty"
gem "eventmachine" "1.0.0.beta.4.1"
gem "thin"
Now, "bundle install" fails with a different error:
Could not find gem 'eventmachine1.0.0.beta.4.1 (>= 0) ruby' in any of the gem sources listed in your Gemfile.
As I mentioned, this version was successfully installed, and it appears in the local repository.
Please help to make "bundle" "happy" with the right 'eventmachine' version.
Sorry if I missed something basic, or failed to find answer already published.
I think you are missing a comma in this line of the last Gemfile:
gem "eventmachine", "1.0.0.beta.4.1"

Resources