Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3332778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:43:27+00:00 2026-05-17T23:43:27+00:00

For each species, I have many datasets. For each dataset, I have many phenotypes.

  • 0

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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:43:27+00:00Added an answer on May 17, 2026 at 11:43 pm

    I found an imperfect solution, which is the :path option on resources().

    resources :species do
      resources :datasets do
        resources :phenotypes, :path => ""
      end
    end
    

    This gives me a slight variation on the routes I had wanted, and three controllers instead of two, which is not ideal — but importantly, it works.

    My paths are now of the form /species/Hs/datasets/mcgary/1 (for phenotype 1).

    I also had to write some helper methods in ApplicationHelper. These make it a bit easier to have triply-nested resources.

    def phenotype_path(phenotype, dataset=nil, species=nil)
      dataset ||= phenotype.dataset
      species ||= phenotype.species
      File.join(phenotypes_path(dataset, species), phenotype.id.to_s)
    end
    
    def phenotypes_path(dataset, species=nil)
      species ||= dataset.species
      File.join(species_path(species.abbrev), "datasets", dataset.name)
    end
    
    def edit_phenotype_path(phenotype, dataset=nil, species=nil)
      File.join(phenotype_path(phenotype,dataset,species), "edit")
    end
    
    def new_phenotype_path(dataset, species=nil)
      File.join(phenotypes_path(dataset, species), "new")
    end
    
    alias :dataset_path :phenotypes_path
    
    def edit_dataset_path(dataset, species=nil)
      File.join(dataset_path(dataset, species), "edit")
    end
    
    def dataset_path(dataset, species=nil)
      species ||= dataset.species
      File.join(species_path(species.abbrev), "datasets", dataset.name)
    end
    
    def datasets_path(species)
      species_datasets_path(species.abbrev)
    end
    

    Unfortunately, these paths sometimes seem to conflict with the autogenerated paths. I’m not sure which module holds those paths, so it’s difficult to rewrite them.

    The other issue is that I can’t quite figure out how to do species_path(species) and have it use the abbreviation. Instead, I have to do species_path(species.abbrev).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have many time series, each one representing a plant species. I think there
Each of my clients can have many todo items and every todo item has
Each book can have many authors. And each author can author many books. class
Each year at Thanksgiving, my family has drawn names out of a hat to
Each of our users is assigned to a primary organizational unit (OU) based on
I have a list of URLs such as, http://www.mywebsite.com/page.php?genus=A_GENUS&species=A_SPECIES&id=12345 . I would like to
I have the following method: def speciate chem_formula.each { |chemical| @chem_species = chemical.scan(/[A-Z][^A-Z]*/) puts
I've got a data frame with far too many rows to be able to
Each of my user's have a set number of slots for storage. They can
I have a dataframe: > df <- data.frame( + Species = rep(LETTERS[1:4], times=c(5,6,7,6)), +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.