开发者

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 mach开发者_StackOverflow中文版ine 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.


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/


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


Simply run bundle install --without production

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜