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

  • Home
  • SEARCH
  • 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 7185883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:30:49+00:00 2026-05-28T18:30:49+00:00

I have a Company which has Projects within them. As time goes on we

  • 0

I have a “Company” which has “Projects” within them. As time goes on we now need to add “Links” that are related to “Projects”. My routes currently look like the following:

resources :companies do
  resources :projects do
    resources :links
  end
end

This seems wrong due to the nesting 2 levels deep. I also no longer have new_company_project_path(@company) anymore if I nest like this which now denies me to ever creating projects for a company.

I will need to add other models to relate to Projects in the coming months.

Here is my Projects model and my Links model as well..

class Link < ActiveRecord::Base
  attr_accessible :link_name, :url, :description

  belongs_to :project
end

class Project < ActiveRecord::Base
  belongs_to :company
  belongs_to :user

  validates :title, :presence => true

  validates :description, :presence => true,
                          :length   => { :minimum => 10 } 
end

It would seem nesting is not the proper way. If nesting is not the proper way, how does one go about saving the association? For example, in my current controller I save my nested objects by doing this:

class ProjectsController < ApplicationController
  before_filter :authenticate_user!
  before_filter :find_company

  def new
    @project = @company.projects.build
  end

  def create
    @project = @company.projects.build(params[:project])
    if @project.save
      flash[:notice] = "Project has been created."
      redirect_to [@company, @project]
    else
      flash[:alert] = "Project has not been created."
      render :action => "new"
    end
  end

  private
    def find_company
      @company = Company.find(params[:company_id])
    end
end

I can’t find too much info on this subject and the books I read before used nesting routes only 1 level deep and others don’t nest at all.

So, what is the best way to do this so that I can have “Links” and other models related to “Projects” while “Projects” remain related to “Companies”?

  • 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-28T18:30:50+00:00Added an answer on May 28, 2026 at 6:30 pm

    You can handle it with shallow nested routes like this:

    resources :companies do
      resources :projects
    end
    
    resources :projects do
      resources :links
      resources :sausages
      resources :patties
    end
    

    Then you have routes like new_company_project_path, new_project_link_path, etc.

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

Sidebar

Related Questions

I have a table articles that has a column company which has list of
My company has a common code library which consists of many class libary projects
I have been researching a few different apps lately for my company which are
I have an company asp.net website with textboxes which may contain several hundred words.
Most of the software company have old software which continue maintain, and they also
My company would dearly like to have an iPhone app which, among other functions,
I have a page which contains profiles of various members of a company and
I have a table which contains a list of products for a company. They
For our company I'd like to have a Python based IRC bot which checks
I have a Rails 3.2.2 application which is a simple company intranet, however although

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.