Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>[Update]</strong></p> <p>While the solution under "old answer" will work for general problems, this section is to answer your specific question after clarification from your comment.</p> <p>You should be able to set environment variables exactly like you specify in your question. As an example, I have a Heroku app that uses HTTP basic authentication.</p> <pre><code># app/controllers/application_controller.rb class ApplicationController &lt; ActionController::Base protect_from_forgery before_filter :authenticate def authenticate authenticate_or_request_with_http_basic do |username, password| username == ENV['HTTP_USER'] &amp;&amp; password == ENV['HTTP_PASS'] end end end # config/initializers/dev_environment.rb unless Rails.env.production? ENV['HTTP_USER'] = 'testuser' ENV['HTTP_PASS'] = 'testpass' end </code></pre> <p>So in your case you would use</p> <pre><code>unless Rails.env.production? ENV['admin_password'] = "secret" end </code></pre> <p>Don't forget to restart the server so the configuration is reloaded!</p> <p><strong>[Old Answer]</strong></p> <p>For app-wide configuration, you might consider a solution like the following:</p> <p>Create a file <code>config/application.yml</code> with a hash of options you want to be able to access:</p> <pre><code>admin_password: something_secret allow_registration: true facebook: app_id: application_id_here app_secret: application_secret_here api_key: api_key_here </code></pre> <p>Now, create the file <code>config/initializers/app_config.rb</code> and include the following:</p> <pre><code>require 'yaml' yaml_data = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'application.yml'))).result) APP_CONFIG = HashWithIndifferentAccess.new(yaml_data) </code></pre> <p>Now, anywhere in your application, you can access <code>APP_CONFIG[:admin_password]</code>, along with all your other data. (Note that since the initializer includes <code>ERB.new</code>, your YAML file can contain ERB markup.)</p>
    singulars
    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