For each species, I have many datasets. For each dataset, I have many phenotypes. The datasets have names which, within a species, are primary keys. The species, too, have string primary keys (e.g., Hs for Homo sapiens). So, I want to be able to specify a phenotype as follows:
/species/Hs/mcgary/1
where mcgary is the name (slug) of the phenotype set.
I understand that I can get this kind of result by putting the following lines in my routes.rb file:
match "/species/:species_id/:dataset(/:id/:action)" => 'phenotypes'
match "/species/:species_id/:dataset/:id" => 'phenotypes#show'
Phenotypes is the phenotype controller. Species has a controller, but Dataset does not -- its functions are handled by Species' and Phenotype's controllers.)
Unfortunately, that doesn't guarantee that the paths will work, e.g., edit_species_dataset_phenotype_path
. I'm not quite sure how to write that instruction in routes.rb. One possibility is to have, in addition to the match instructions, the following:
resources :species do
resources :dataset do
resources :phenotypes
end
end
and just set up a redirect. But that's awkward. Is there some way I can use the match notation to get the paths working? Love the new routes, but wish the documentation had some full examples in it.
I also notice that if I do something like edit_species_dataset_path(species, dataset), I can get the /species/:species_id/:phenotype_set_id
route format -- but I'm not sure how to get it to use :abbrev on Species instead, other than to type species.abbrev every time. Is there a way to tell it to use that column by default, instead of id?
Many thanks. (And yes, I realize nested routes like this get awkward. I'm okay with that.)