Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 namespaced routes: how to link *from* a namespace back to the global namespace? [REVISED]
    primarykey
    data
    text
    <p>I have a common layout file, used site-wide. It contains links like:</p> <pre><code>&lt;%= link_to("Home", { :controller =&gt; :home, :action =&gt; :index }) %&gt; </code></pre> <p>And other common links in the header/footer etc.</p> <p>All of my controllers are simply under the <code>app/controllers/</code> directory. But I've added a namespace for admins (to ban users etc):</p> <pre><code>namespace :admin do resources :users end </code></pre> <p>My admin namespace isn't any different in look &amp; feel, so it uses the same layout as the rest of the site. Which is causing some issues, since all of my <code>link_to</code> and <code>url_for</code> calls are being mis-interpreted as, say:</p> <pre><code>&lt;%= link_to("Home", { :controller =&gt; "admin/home", :action =&gt; :index }) %&gt; </code></pre> <p>Which crashes the app, as no such route exists. Do I have to go through all of my templates used by the layout and change the controller portion of the <code>link_to</code> with a leading slash, or is there a better way to make all of my top-level routes functional even under the admin namespace? I link out of the admin namespace into the top-level namespace for lots of things, so it would be good if I didn't really have to give any special consideration to my <code>link_to</code> calls.</p> <p>In summary, when under a namespaced controller, do you have to prefix all <code>:controller</code> parameters in <code>link_to</code> with a leading slash in order to break out of the namespace?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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