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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:52:06+00:00 2026-06-08T16:52:06+00:00

I have a Rails application which has an Employee model, a Skill model and

  • 0

I have a Rails application which has an Employee model, a Skill model and a Department model.

class Employee < ActiveRecord::Base
  belongs_to :department
  has_and_belongs_to_many :skills
  attr_accessible :email, :firstname, :name, :twitter
end

class Skill < ActiveRecord::Base
  has_and_belongs_to_many :employees
  attr_accessible :name
end

class Department < ActiveRecord::Base
  attr_accessible :name
end

I was trying to write down the routes for this, but this is where I run into trouble.

I think it makes sense to do

resources :employees do
  resource :department
  resources :skills
end

however, I also want to be able to create skills and departments independently. I only need to be able to ‘hook up’ a department and a skill to an employee. The routes, like this, make sense (/employees/:id/skills, /employees/:id/department), but like I said, I would like to be able to do

/departments
/skills
/skills/new

etc..

I could do

EmployeeList::Application.routes.draw do

  resources :departments
  resources :skills

  resources :employees do
    resource :department
    resources :skills
  end
end

and this provides me with the routes I want, but it looks like really bad practice having the resources listed twice in my routes.rb file. How should I do this?

  • 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-06-08T16:52:07+00:00Added an answer on June 8, 2026 at 4:52 pm

    if, as you wrote “I also want to be able to create skills and departments independently. I only need to be able to ‘hook up’ a department and a skill to an employee.” then this is clearly not a case for nested resources imho. Nested Resources can only exist “within” their “surrounding” resource. A simple 1:n relation with belongs_to and has_many should be what you want, thus in routes.rb:

    EmployeeList::Application.routes.draw do
      resources :departments
      resources :skills
      resources :employees
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model in my rails application which is class Person < ActiveRecord::Base
I have an application in Rails 3.2.1 with a model which has a column
I have a database labor which contains the tables that the rails application has
Here's our basic requirements: We have a base Rails application, which is being actively
In my Rails application I have a simple controller which also has an action
I have a Rails project which has a Postgres database for the actual application
I have a users_manager engine which has a User model class. In an other
I have a rails application in which pages has many comments. So the relationships
I have a RAILS 3.x application developed locally using MySQL which has data which
I've started a Rails application with Devise and CanCan. I have users which has

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.