Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use conditionals in Gemfile

I have these groups in my Gemfile:

group :development, :test do
   gem 'sqlite3'
end
group :production do
  gem 'mysql'
end

The development machine does not have MySQL installed, which is why I have only listed MySQL in the production group. But when I try to run Rails on the development machine I get this:

$> RAILS_ENV=development ./script/rails 
Could not find gem 'mysql (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

Obviously I could fix this by installing MySQL, but I would like to know the correct solution instead of installing unneeded software.

like image 782
Richard Avatar asked Mar 16 '11 09:03

Richard


2 Answers

You do need to have the gem installed. Bundler (the underlying gem manager for Rails) requires it so you can resolve potential conflicts of dependencies in development rather than finding out you have gem conflicts when you roll to production. Yehuda (builder of Bundler) wrote a blog post on it, look in the section titled "Consistency".

http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

like image 103
Brandon Avatar answered Sep 24 '22 23:09

Brandon


did you rerun "bundle install" after changing your Gemfile?

like image 29
noli Avatar answered Sep 22 '22 23:09

noli