Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>the documentation seems to indicate this exact behavior is by design:</p> <blockquote> <p>:shallow - If true, paths for nested resources which reference a specific member (ie. those with an :id parameter) will not use the parent path prefix or name prefix.</p> </blockquote> <p>(from <a href="http://api.rubyonrails.org/classes/ActionController/Resources.html#M000501" rel="nofollow noreferrer">http://api.rubyonrails.org/classes/ActionController/Resources.html#M000501</a>)</p> <p>Since using the :shallow option will cause your :path_prefix to be ignored in some cases, if you must always have this prefix you should consider removing the :shallow option. Here's an alternate solution that appears to do what you need:</p> <pre><code>map.with_options :path_prefix =&gt; "blog" do |blog| blog.resources :posts do |posts| posts.resources :comments, :only =&gt; [:index, :create, :new] end blog.resources :comments, :except =&gt; [:index, :create, :new] end </code></pre> <p>Resulting in these routes:</p> <pre><code># posts GET /blog/posts {:controller=&gt;"posts", :action=&gt;"index"} # POST /blog/posts {:controller=&gt;"posts", :action=&gt;"create"} # new_post GET /blog/posts/new {:controller=&gt;"posts", :action=&gt;"new"} # edit_post GET /blog/posts/:id/edit {:controller=&gt;"posts", :action=&gt;"edit"} # post GET /blog/posts/:id {:controller=&gt;"posts", :action=&gt;"show"} # PUT /blog/posts/:id {:controller=&gt;"posts", :action=&gt;"update"} # DELETE /blog/posts/:id {:controller=&gt;"posts", :action=&gt;"destroy"} # post_comments GET /blog/posts/:post_id/comments {:controller=&gt;"comments", :action=&gt;"index"} # POST /blog/posts/:post_id/comments {:controller=&gt;"comments", :action=&gt;"create"} # new_post_comment GET /blog/posts/:post_id/comments/new {:controller=&gt;"comments", :action=&gt;"new"} # edit_comment GET /blog/comments/:id/edit {:controller=&gt;"comments", :action=&gt;"edit"} # comment GET /blog/comments/:id {:controller=&gt;"comments", :action=&gt;"show"} # PUT /blog/comments/:id {:controller=&gt;"comments", :action=&gt;"update"} # DELETE /blog/comments/:id {:controller=&gt;"comments", :action=&gt;"destroy"} </code></pre> <p>Hope this helps!</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