title: Combining shallow and non-shallow routes on a single Rails resource
body: <p>Let's say I have a <code>Magazine</code> model and <code>Ad</code> model, such that <code>Magazine :has_many =&gt; :ads</code>. I have setup my nested resource routing as follows:</p>
  
  <pre><code>resources :magazines do 
    resources :ads, :shallow =&gt; true do
      get 'search', :action =&gt; :search, :on =&gt; :collection
    end
  end
  </code></pre>
  
  <p>My goal here is to be able to access the default CRUD routes created by Rails resources, plus a search route, on both a nested and shallow level. I want the user to be able to restrict his search from within the context of a given Magazine, or search all Ads regardless of parent Magazine, because some Ads won't have parent Magazines. <strong>In other words, I want to be able to:</strong></p>
  
  <pre><code>/magazines/1/ads/new
  /ads/new
  
  /magazines/1/ads/search
  /ads/search
  
  # ... all standard CRUD routes ...
  </code></pre>
  
  <p>My concern is that the path variables in the views rely on things like <code>new_magazine_ad_path(@magazine)</code>. Won't accessing a route like <code>/ads/index</code> (which should contain a link to create a new ad) break on encountering the <code>new_magazine_ad_path(@magazine)</code> helper without any <code>@magazine</code> instance to guide it?</p>
  
  <hr>
  
  <p>P.S.:
  Normally, I would try all this out myself to see what worked, but I'm stuck right now with the above setup - I can only reach the edit, delete, show, and update shallow routes:</p>
  
  <pre><code>/ads/:id
  /ads/:id/edit
  /ads/:id (put)
  /ads/:id (delete)
  </code></pre>
  
  <p>and no new or index routes:</p>
  
  <pre><code>/ads/index
  /ads/new
  </code></pre>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>So Shreyas proposed creating two controllers, one to handle the nested Ad, and one to handle the shallow Ad. This makes sense, but it leaves me duplicating all the view code just to change the path helpers from <code>magazine_ad_path(@magazine)</code> to <code>ad_path</code>. <strong>Any ideas on a DRY'er approach to handling the view changes?</strong> All the other view code is identical.</p>