title: Ruby on Rails: Where to define global constants?
body: <p>I'm just getting started with my first Ruby on Rails webapp. I've got a bunch of different models, views, controllers, and so on. </p>
  
  <p>I'm wanting to find a good place to stick definitions of truly global constants, that apply across my whole app. In particular, they apply both in the logic of my models, and in the decisions taken in my views. I cannot find any DRY place to put these definitions where they're available both to <em>all</em> my models and also in all my views.</p>
  
  <p>To take a specific example, I want a constant <code>COLOURS = ['white', 'blue', 'black', 'red', 'green']</code>. This is used all over the place, in both models and views. Where can I define it in just one place so that it's accessible?</p>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>Constant class variables in the model.rb file that they're most associated with, such as <code>@@COLOURS = [...]</code>. But I couldn't find a sane way to define it so that I can write in my views <code>Card.COLOURS</code> rather than something kludgy like <code>Card.first.COLOURS</code>.</li>
  <li>A method on the model, something like <code>def colours ['white',...] end</code> - same problem.</li>
  <li>A method in application_helper.rb - this is what I'm doing so far, but the helpers are only accessible in views, not in models</li>
  <li>I think I might have tried something in application.rb or environment.rb, but those don't really seem right (and they don't seem to work either)</li>
  </ul>
  
  <p>Is there just no way to define anything to be accessible both from models and from views? I mean, I know models and views should be separate, but surely in some domains there'll be times they need to refer to the same domain-specific knowledge?</p>