Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>after all 'routes.rb' is just a simple ruby file, so why not use ruby code and maybe even make a method to generate the necessary routes .. lets have a look at a simple example using an array of resources, if you want to use nested resources you might want to modify the method to use hash-chains in order to pass the resources you want to add a member: </p> <pre><code>def add_nested_resource(toadd=nil, controller=nil, resources=[]) return if toadd.nil? || controller.nil? || ressources.empty? resources.each { |x| resources x do resources toadd, :controller =&gt; controller end } end add_nested_resource(:notes, "notes", [:resource1, :resource2, ..., :resourceX] </code></pre> <p>would be equivalent to </p> <pre><code>resources :resource1 do resources :notes, :controller =&gt; "notes" end resources :resource2 do resources :notes, :controller =&gt; "notes" end . . . resources :resourceX do resources :notes, :controller =&gt; "notes" end </code></pre> <p>That way you could simply write a lot of routes with few effort. Within the notes_controller of course you might have to distinguish which resource has called on it, I usually add a hidden field in the according forms where I leave a 'classified' name of the object that nests the nested object ... like </p> <pre><code>&lt;%= form_for ... someform for resource1... do |f| %&gt; ... &lt;%= hidden_field_tag :nesting_object, "Resource1" %&gt; ... &lt;% end %&gt; </code></pre> <p>Hope this helps you through your trouble...</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