title: Rails constant lookup
body: <p>I have a question about setting up constants in Rails project. </p>
  
  <p>From Dan Chak's Enterprise Rails book, he explains that constant lookup code like below gets executed only once when the app starts. However, looking at the log, I think it gets run every time I use the constant. </p>
  
  <pre><code>class Role &lt; ActiveRecord::Base
    USER = Role.find_by_key('user')
    ADMIN = Role.find_by_key('admin')
  end
  </code></pre>
  
  <p>This definitely allows cleaner code as I can do something like: </p>
  
  <pre><code>current_user.role = Role::ADMIN
  </code></pre>
  
  <p>As an alternative, I read about <code>ActiveSupport::Memoizable</code>, but I want to confirm this setup results in multiple db lookup before changing my code around. </p>
  
  <p>Thanks for your input!</p>