Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting something different than standard nesting resources
    primarykey
    data
    text
    <p>I was wondering if it would be possible to nest resources differently than what I usually see. </p> <p>Usually, resources go something like this:</p> <pre><code>resources :article do resources :comment end </code></pre> <p>And this produces the URL <code>/article/:article_id/comment</code> [for comment#index, of course]</p> <p>However, I'm wondering if I could do this differently to get something like</p> <pre><code>/article/comment [excluding :article_id] </code></pre> <p>Article would have all of its other normal routes, and comment would behave as it would in the first example. Is there a way to do this, so that I could keep /comment connected with comments_controller, or do I need to relocate all of the comment methods into the articles_controller? I'd prefer to avoid that, because it causes headaches later. </p> <p>**You're probably asking why I'd ever need to do this in this context. Truth is, I'm doing it in a different context, but this one is easier to explain. </p> <p>EDIT: </p> <p>The real purpose is different than the example. I want a controller, 'employee_benefits', to be a regular controller and have regular resources. However, I'd like to be able to do something like /employee_benefits/new_type. A type of benefit is something that appears in the form when creating a new employee_benefit. I'd like to be able to do things like /employee_benefits/edit_type[:id], /employee_benefits/delete [well not exactly]</p> <p>I think namespacing is the way to go, but I'm not completely sure how to do it. </p> <p>More EDIT:</p> <p>I'm currently using these resources:</p> <pre><code> match '/benefits/new_type' =&gt; 'company_benefits#new_type' match '/benefits/create_type' =&gt; 'company_benefits#create_type' match '/benefits/types' =&gt; 'company_benefits#types' match '/benefits/type' =&gt; 'company_benefits#types' </code></pre> <p>Instead of </p> <pre><code> resources :company_benefits, :path =&gt; '/benefits', :as =&gt; :benefits do &lt;not using this line of code&gt; resources :company_benefit_types &lt;/not using this line of code&gt; end </code></pre>
    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.
    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