title: How to use cattr_accessor to define config in a Rails initializer
body: <p>Given the following class (this is the actual class there is no other code) </p>
  
  <pre><code>class PageRepo
    cattr_accessor :root_path
  end 
  </code></pre>
  
  <p>and initializer file </p>
  
  <pre><code>PageRepo.root_path = Rails.root.join("content")
  </code></pre>
  
  <p>When I run 
  <code>rails console</code> </p>
  
  <pre><code>PageRepo.root_path 
  =&gt; PageRepo.root_path
  =&gt; #&lt;Pathname:/Users/blah/my_rails_app/content/pages&gt;
  </code></pre>
  
  <p>However when I try to access this in my rails controller the root_path value is <strong>nil</strong>. (I've inspected this with web_console.)</p>
  
  <p>No other class subclasses or is a parent of the PageRepo class and I'm not setting the root_path to nil anywhere at class level or instance level after the initializer stage. I have restarted spring and my server multiple times to no avail. </p>
  
  <p>Is there something I'm not aware of when it comes to either Rails initializers or cattr_accessor?</p>
  
  <p><strong>Update</strong> </p>
  
  <p>I'd like to set the path like this because throughout my code I will be initialising a PageRepo instance and the path will not change. However, it may change across different environments. I.e. in development it the path will be different than that of the test and production environments. Whilst I could just do </p>
  
  <p><code>
  def initialize
    @root_path = ENV['ROOT_PATH']
  end
  </code></p>
  
  <p>I'd prefer to not force the programmer to use ENV VARS to do this and hence my attempt above. </p>