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 868223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:06:14+00:00 2026-05-15T10:06:14+00:00

I have three relevant models: Companies, Projects, and Links, and I am trying to

  • 0

I have three relevant models: Companies, Projects, and Links, and I am trying to create a system where we generate routes according to the Links they create, for example:

www.site.com/the_company's_specific_path/one_of_company's_links

One company has_many :projects, one project has_many :links.

Summary of the structure:

#Company table
company.id
company.path # such as 'Bechtel'

#Project table
project.id
project.company_id

#Link table
link.id
link.link # such as 'railwayproject'
link.project_id
link.company_id # some links may be tied to the company and not one specific project

#Final route generated: www.site.com/bechtel/railwayproject

How can I set up this system so:

  • Part 1 of the route specifies company.path (along the lines of @company = Company.find_by_path(params[:path]))
  • Part 2 finds link (along the lines of @link = Link.find_by_link_and_company_id(params[:link],@company.id))
  • Upon entering this URI/URL the user enters ‘show’ where they see information on the project or company. (When a link isn’t tied specifically to a project we show ‘list’ instead, displaying all the company’s projects.)

I apologize if for any reason the above is unclear. I have tried to explain as best I can! Thanks.

  • 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-15T10:06:14+00:00Added an answer on May 15, 2026 at 10:06 am

    You should check out the documentation for ActionController::Routing, ActionController::Resources for RESTful routes, and a handy Rails Guide on the topic. There are also a number of Railscasts regarding routes.

    Something as simple as map.connect :path/:link, :controller => :companies would work, but it may cause some problems depending on your existing routes and is not RESTful. If it does not cause any conflicts, this would allow you to do what you’re asking for.

    You can add constraints to the route using the :requirements option to narrow down what is considered a match:

    map.company_link :company/:link, :requirements => { :company => /[\w\-]+/, :link => /[\w\-]+/ }
    

    This would only match word and dash (‘-‘) characters in the url, and I believe the default routes will still work properly. I also made it a named route with map.company_link so Rails creates a set of url helpers allowing easy reference to your route: company_link_path(:company => "Bechtel", :link => "railwayproject")

    If you want to stick with the REST way of doing this would be:

    map.resource :companies do |company|
      company.resources :links
    end
    

    /companies/1/links/2 would get passed to the show action of the links_controller with the company and link ids as params. This is explained further in the nested resources section of the previously mentioned Rails Guide. Normally, you would use the :shallow => true option, because the link id of 2 is already unique and does not need to be nested under companies. The real value of the nested route is showing all of the links with /companies/1/links and all other actions going directly to the individual link /links/2.

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

Sidebar

Related Questions

I have three models ( User , Tag , Product ) and they interact
I have three files: lib.c lib.h => They should be built as a .so
I have three models: Post ( has_many votes as votable ), Comment ( has_many
I have three projects: TestNHibernateMappings - A console project WebApplicationPbiBoard - An Asp.Net MVC
What am I trying to do? I have three fields (1 hidden, an id)
Is there a way to generate a scaffold for Rails models that have either
I have three models, booking, room and travellers. Booking has many rooms room has
Have three classes User, Group and Field. Many to many relationship on User /
Have three divs in a container that I want to float over a large
i have three lists with the same number of elements in each other, i

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.