Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm assuming you're testing your engine with a dummy rails app, like the one that would be generated by <a href="https://github.com/josevalim/enginex" rel="noreferrer">enginex</a>.</p> <p>Your engine should be mounted in the dummy app:</p> <p>In <code>spec/dummy/config/routes.rb</code>:</p> <pre><code>Dummy::Application.routes.draw do mount Posts::Engine =&gt; '/posts-prefix' end </code></pre> <p>My second assumption is that your engine is isolated:</p> <p>In <code>lib/posts.rb</code>:</p> <pre><code>module Posts class Engine &lt; Rails::Engine isolate_namespace Posts end end </code></pre> <p>I don't know if these two assumptions are really required, but that is how my own engine is structured.</p> <p>The workaround is quite simple, instead of this</p> <pre><code>get :show, :id =&gt; 1 </code></pre> <p>use this</p> <pre><code>get :show, {:id =&gt; 1, :use_route =&gt; :posts} </code></pre> <p>The <code>:posts</code> symbol should be the name of your engine and NOT the path where it is mounted.</p> <p>This works because the get method parameters are passed straight to <code>ActionDispatch::Routing::RouteSet::Generator#initialize</code> (defined <a href="https://github.com/rails/rails/blob/v3.1.0/actionpack/lib/action_dispatch/routing/route_set.rb#L366" rel="noreferrer">here</a>), which in turn uses <code>@named_route</code> to get the correct route from <code>Rack::Mount::RouteSet#generate</code> (see <a href="https://github.com/rails/rails/blob/v3.1.0/actionpack/lib/action_dispatch/routing/route_set.rb#L451" rel="noreferrer">here</a> and <a href="https://github.com/josh/rack-mount/blob/master/lib/rack/mount/route_set.rb#L216" rel="noreferrer">here</a>).</p> <p>Plunging into the rails internals is fun, but quite time consuming, I would not do this every day ;-) .</p> <p>HTH</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload