Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of my favourite techniques is to put a file containing the constants in directory <code>config/initializers/</code> (all files in this directory are loaded automatically) but with a section for each different Rails environment. e.g.</p> <pre><code> case ENV['RAILS_ENV'] when "development" SYSTEM_EMAIL = ... SYSTEM_EMAIL_SIGNATURE = ... when "staging" SYSTEM_EMAIL = ... SYSTEM_EMAIL_SIGNATURE = ... when "production" SYSTEM_EMAIL = ... SYSTEM_EMAIL_SIGNATURE = ... end </code></pre> <p>If you want, instead, to load up all the constants in one big hash then you can load them as a YAML file. Create two files, one called, say, <code>config/initializers/email_constants.rb</code> and the other <code>config/email_constants.yml</code>. In the latter put something like:</p> <pre><code> development: :system_email: ... :system_email_signature: ... staging: :system_email: ... system_email_signature: ... ... etc ... </code></pre> <p>Then in <code>config/initializers/email_constants.rb</code> put:</p> <pre><code> EMAIL_CONSTANTS = YAML.load_file("#{RAILS_ROOT}/config/email_constants.yml")[RAILS_ENV] </code></pre> <p>This loads the entire YAML file and the assigns the value of the appropriate key (which represents the <code>RAILS_ENV</code>) to <code>EMAIL_CONSTANTS</code>.</p> <p>The advantage of both of these techniques is locality. You can place all the constants that are related to each other (i.e. email constants in this case) in one file. Also, instead of having the same constants spread across three different files (one for each Rails environment) you have them all in one file.</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