Hi everyone!
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.