25696

Rails Gemfile: use one line in development, another in production

We run Unicorn on Heroku in production but use Webrick in development on a local machine. We are unable to install Unicorn on the local machine.

Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.

We're on Rails 3.2.12.

Gemfile:

source 'http://rubygems.org' gem 'rails', '3.2.12' gem 'jquery-rails' # # ========================================================================================= # # #========================================================================================= gem 'mongo' gem 'mongo_mapper' gem 'plucky' gem 'bson_ext' gem 'bson' gem 'newrelic_rpm' gem 'rpm_contrib' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'uglifier', '>= 1.0.3' end

Thanks!

Answer1:

Is it possible to have Rails load the Unicorn gem only in production? Right now, our solution is to comment out the Unicorn gem when running the app locally and uncomment the gem when pushing to Heroku.

Yes, it is possible by the use of groups in Gemfile. Update your Gemfile like follows for the unicorn gem in production only:

# Gemfile group :production do gem 'unicorn' end

Since WEBrick is the default web server for rails apps, you wouldn't need to specify anything for development group.

Running bundle install after the Gemfile update will still install the production gems. This is definitely a good thing to do as you want to make sure the gems you are planning to use in production work correctly with your application from the development phase of project.

To skip installation of production group gems:

bundle install --without production

A point to be noted about the --without production option is that the subsequent calls to bundle install and bundle update are also going to skip installing and updating production gems. To disable this you'd need to remove the lineBUNDLE_WITHOUT: production from your app_root/.bundle/config:

# app_root/.bundle/config BUNDLE_WITHOUT: production

Recommend

  • Mongo Connection Failure
  • Rails 4, Carrierwave-aws, images uploaded to Amazon s3 locally, but not in production (Openshift)
  • In Rails, why there is a new Gemfile.lock when no bundle or bundle install was run? (and a new Gemfi
  • How can I cons a list of pairs on to auto-mode-alist?
  • What to do if “git push heroku master” failed?
  • Errno::ECONNREFUSED No connection could be made because
  • Meteor oplog for Mongo 2.6
  • How to extract a plane from a 3D variable in FiPy (3D to 2D)
  • Migrating from java 1.4 ,EJB 1 to Java 6 and EJB 3 [closed]
  • MongoDB GeoJSON “Can't extract geo keys from object, malformed geometry?” when inserting type P
  • Mongodb update() vs. findAndModify() performace
  • When executing an array of tasks asynchronously, shouldn't it take as long as the longest runni
  • Heroku push rejected - Hartl's Rails 3.2 tutorial
  • Error while using PDF Kit
  • Two Tables Serving as one Model in Rails
  • How to override value that appears in a dropdown in the rails_admin gem
  • Loading .coffee files via a view in Rails
  • ImageMagick, replace semi-transparent white with opaque white
  • Cannot connect to cassandra from Spark
  • Pass value from viewmodel to script in zk
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Optimizing database types to compact database (SQLite)
  • How do I fake an specific browser client when using Java's Net library?
  • Cross-Platform Protobuf Serialization
  • Javascript + PHP Encryption with pidCrypt
  • Websockets service method fails during R startup
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • jQuery tmpl and DataLink beta
  • Do I've to free mysql result after storing it?
  • QuartzCore.framework for Mono Develop
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • How to disable jQuery.jplayer autoplay?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy