Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails Namespacing and Nested Routing
    primarykey
    data
    text
    <p>I'm learning Ruby and Rails and trying to figure out the most correct path to go for my scenario regarding possibly namespacing as well as routing.</p> <p>Say I have a 'Zoo' model as well as 'Species' model. I also need a relationship between them to tell what Species are in what Zoos (a Zoo has many Species, which will also have their own properties such as qty, location, etc)</p> <p>I would like my routes to be like:</p> <pre><code>/zoo /zoo/:id ... /zoo/:zoo_id/species/ /zoo/:zoo_id/species/:id ... /species /species/:id </code></pre> <p>I have tried messing with modules, namespaces, route scopes, etc. I can't seem to get it how I'd like and think there has to be a better/natural way to do this. The problem is mainly due to the fact that I have a species model as well as a species model of zoo (I've tried namespacing to Zoo and creating a Zoo::Zoo and Zoo::Species classes, creating a ZooSpecies class, and adjusting routes for those scenarios, etc) </p> <p>From an organizational standpoint, it would be great to be able to have a Zoo class as well as a Zoo namespace, to have Zoo::Species and such, but that is not possible.</p> <p>What is the proper way to organize something like this?</p> <p><strong>Update: My current setup...</strong></p> <pre><code>Zoo Module Zoo::Zoo Class Zoo::Species Class Species Class </code></pre> <p>Routes:</p> <pre><code>resources :zoos, path: 'zoos' do resources :zoo_species, path: 'species', as: 'species', controller: 'zoo/species' end </code></pre> <p>And a <code>Zoo</code> controller and a <code>Zoo::Species</code> controller. I feel like I'm getting closer to the desired result, but fighting against the framework more than I think I should. Still running into some issues properly setting up the relationships and paths, having to specify a lot of config values</p>
    singulars
    1. This table or related slice is empty.
    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