Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of common practices to handle this situation if you don't want to use Git hooks or other methods to modify the actual code upon deploy.</p> <p><strong>Environment Based Configuration</strong></p> <p>If you don't mind having the production values your configuration settings in your repository, you can make them environment based. I sometimes use something like this:</p> <pre><code># config/application.yml default: facebook: app_id: app_id_for_dev_and_test app_secret: app_secret_for_dev_and_test api_key: api_key_for_dev_and_test production: facebook: app_id: app_id_for_production app_secret: app_secret_for_production api_key: api_key_for_production # config/initializers/app_config.rb require 'yaml' yaml_data = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'application.yml'))).result) config = yaml_data["default"] begin config.merge! yaml_data[Rails.env] rescue TypeError # nothing specified for this environment; do nothing end APP_CONFIG = HashWithIndifferentAccess.new(config) </code></pre> <p>Now you can access the data via, for instance, <code>APP_CONFIG[:facebook][:app_id]</code>, and the value will automatically be different based on which environment the application was booted in.</p> <p><strong>Environment Variables Based Configuration</strong></p> <p>Another option is to specify production data via environment variables. Heroku allows you to do this via <a href="http://devcenter.heroku.com/articles/config-vars" rel="nofollow">config vars</a>.</p> <ol> <li><p>Set up your code to use a value based on the environment (maybe with optional defaults):</p> <pre><code>facebook_app_id = ENV['FB_APP_ID'] || 'some default value' </code></pre></li> <li><p>Create the production config var on Heroku by typing on a console:</p> <pre><code>heroku config:add FB_APP_ID=the_fb_app_id_to_use </code></pre></li> </ol> <p>Now <code>ENV['FB_APP_ID']</code> is <code>the_fb_app_id_to_use</code> on production (Heroku), and <code>'some default value'</code> in development and test.</p> <p>The Heroku documentation linked above has some more detailed information on this strategy.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload