title: How do I access all routes, when an App and an included AppEngine gem define controllers with the same name?
body: <p>I have an engine (developed by me / the company I work for) that we use on several different projects.  I just converted it  to work with rails 3.1 w/ assets pipeline and everything seems to be working... for the most part.</p>
  
  <p>My problem is that I need to extend the functionality of the <code>UsersController</code> with a little bit of app-specific spice, but I'm not sure about the best way to do it.  The engine doesn't define a <code>Users#show</code> action, but this app does need it, so I added to the routes file:</p>
  
  <pre><code>JobEngine::Application.routes.draw do
    root :to =&gt; 'home#index'
  
    resource :users, :only =&gt; [:show]
    resources :jobs, :only =&gt; [:show]
  end
  </code></pre>
  
  <p>Then in my application I created the UsersController:</p>
  
  <pre><code>class UsersController &lt; MyEngine::UsersController
    def show
    end
  end
  </code></pre>
  
  <p>Then I made a <code>users/show.html.haml</code> view, I've stripped it down to only show one of the problem lines:</p>
  
  <pre><code>= link_to "Somewhere", job_path(3)
  </code></pre>
  
  <p>This gives me an error that reads <code>undefined method 'job_path' for #&lt;#&lt;Class:0x00000102d69900&gt;:0x00000102d4ed30&gt;</code></p>
  
  <p>Which is bizarre because <em>before</em> I made my app's <code>UsersController</code> inherit from <code>MyEngine::UsersController</code> it worked just fine.</p>
  
  <p>When I do <code>rake routes</code> in the console, there are these lines:</p>
  
  <pre><code>users GET   /users(.:format)    {:action=&gt;"show", :controller=&gt;"users"}
  job GET     /jobs/:id(.:format) {:action=&gt;"show", :controller=&gt;"jobs"}
  </code></pre>
  
  <p>I can alter the class definition to be:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
  </code></pre>
  
  <p>and then the link works just fine.  However, the engine's controller <code>MyEngine::UsersController</code> already inherits from <code>ApplicationController</code>.  I can put code into my app's <code>ApplicationController</code> (like a <code>before_filter</code>) and it will run as expected, so I know my class definition does ultimately hit my app's <code>ApplicationController</code>, why is the job_path helper not working?</p>
  
  <p>When I change the show action to read:</p>
  
  <pre><code>def show
    job_path(3)
  end
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>ActionController::RoutingError (No route matches {:action=&gt;"show", :controller=&gt;"jobs", :id=&gt;3}):
  app/controllers/users_controller.rb:9:in `show'
  </code></pre>
  
  <p>Which further confuses me because now it actually does recognize job_path as a method, but somehow the router isn't picking up where to go with all the correct parameters.</p>
  
  <p>What am I doing wrong?  What is the correct way to extend engine controller functionality?  I saw <a href="https://stackoverflow.com/questions/2964050/rails-engines-extending-functionality">the extending engine functionality question here.</a></p>
  
  <p>And followed that code example, changing my class definition to instead re-open <code>MyEngine::UsersController</code> but I still get the exact same results concerning <code>job_path(NUMBER)</code></p>
  
  <p>UPDATE:</p>
  
  <p>Ok I sort of figured out what's going on.  Let's say your engine has a job_path route, and your application has a job_path route.  If you're on a page that was accessed via an engine's controller, you can call the engine's helper with just <code>job_path</code>, but you can also call the main application's helper with <code>main_app.job_path</code>.</p>
  
  <p>Likewise, if you're on a page accessed via one of your application's controllers, you access the engine's helper with <code>my_engine.job_path</code> and your own application's helper with <code>job_path</code>.  This is assuming that you have something like <code>mount MyEngine::Engine =&gt; "/my_engine", :as =&gt; 'my_engine'</code>.</p>
  
  <p>When you inherit an engine controller from your application, it then completely changes your route helpers to think you're in the context of the engine through the controller/view lifecycle.  So to fix my problem all I really have to do is change it to be <code>main_app.job_path(3)</code> and it works.</p>
  
  <p>I'm not completely satisfied with this solution because it feels a little...weird.  Maybe I have a partial on this page that will be used on a separate non-inheriting page.  Now the link helper will only work for one of the two pages, but never both =\  Am I missing something here...?</p>