title: How to run some code only when the rails console starts, kind of like an rc file?
body: <p>Is there a way to execute some code that is run only when the console starts? Kind of like an rc file (<code>.bashrc</code>, <code>.zshrc</code>, etc.)? I find myself always doing certain things a lot.</p>
  
  <p>For example, where would I put this</p>
  
  <pre><code>u = User.find_by_username('my_console_user')
  </code></pre>
  
  <p>so that <code>u</code> is available in <code>rails console</code>?</p>
  
  <p>I have resorted to this, the use of <code>$</code> as global variable declaration, and the use of the obscure <code>console do</code>. I assume there is something more elegant somehow...</p>
  
  <pre><code>  class Application &lt; Rails::Application
      #this is only executed in the console, also doens't seem to be documented anywhere but here: https://github.com/rails/rails/pull/3139
      console do
        $u1 = User.find_by_username('user1')
        $u2  = User.find_by_username('user2')
      end
  
    end
  </code></pre>