title: Accessing helpers and models from rails engine initializer
body: <p>I'm trying to make a Ruby on Rails engine, and I want the initializer to be able to have access to the helpers and models.<br>
  I'll write below an example, part of the code, and the error that I have. It may not be the recommended way, because I can see that in some cases I'm repeating myself, but it's the first engine I make. </p>
  
  <p>file <strong>lib/my_engine/engine.rb</strong></p>
  
  <pre class="lang-rb prettyprint-override"><code>module MyEngine
    require 'my_engine/functions'
  
    class Engine &lt; ::Rails::Engine
      isolate_namespace MyEngine
      config.autoload_paths += %W( #{config.root}/lib )
    end
  
    class GlobalVars
      attr_accessor :foo
      def initialize
        @foo = MyEngine::Functions.new
      end
    end
  
    class &lt;&lt; self
      mattr_accessor :GLOBAL
      mattr_accessor :USER_CONFIG
  
      self.GLOBAL = MyEngine::GlobalVars.new
      # add default values of more config vars here
      self.USER_CONFIG = 'default config'
    end
  
    def self.setup(&amp;block)
      yield self
    end
  
  end 
  </code></pre>
  
  <p>file <strong>lib/my_engine/functions.rb</strong></p>
  
  <pre class="lang-rb prettyprint-override"><code>module MyEngine
    require '../../app/helpers/my_engine/options_helper'
  
    class Functions
      include MyEngine::OptionsHelper
  
      attr_accessor :some_link
  
      def initialize
        @some_link = get_option('dummy')
      end
    end
  end
  </code></pre>
  
  <p>There is also a controller named <code>OptionsController</code> in <strong>app/controllers/my_engine</strong>, and <code>OptionsHelper</code> in <strong>app/helpers/my_engine/options_helper.rb</strong>:</p>
  
  <pre class="lang-rb prettyprint-override"><code>module MyEngine
    module OptionsHelper
      def get_option(name)
        MyEngine::Option.new
      end
    end
  end 
  </code></pre>
  
  <p>When I try to run the dummy application, this error occurs:</p>
  
  <pre><code>/app/helpers/my_engine/options_helper.rb:4:in `get_option': uninitialized constant MyEngine::Option (NameError)
  </code></pre>
  
  <p>If I change to just <code>Option.new</code>, I have this error:</p>
  
  <pre><code>/app/helpers/my_engine/options_helper.rb:4:in `get_option': uninitialized constant MyEngine::OptionsHelper::Option (NameError)
  </code></pre>
  
  <p>For <code>::MyEngine::Option.new</code>, I have:</p>
  
  <pre><code>/app/helpers/my_engine/options_helper.rb:4:in `get_option': uninitialized constant MyEngine::Option (NameError)
  </code></pre>
  
  <p>For <code>::Option.new</code>, I have:</p>
  
  <pre><code>/app/helpers/my_engine/options_helper.rb:4:in `get_option': uninitialized constant Option (NameError)
  </code></pre>
  
  <p>The dummy application has nothing in it. All helpers and models defined above are in the engine.</p>
  
  <p>Before this, I had other errors because it couldn't access the helper, or the <code>Functions</code> class. I had to add require and include to make it work even if they are placed in the same directory. Also, to work, I had to move <code>GlobalVars</code> from its own file inside engine.rb.</p>
  
  <p>Can somebody show me what I'm doing wrong?</p>