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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:21:08+00:00 2026-06-06T14:21:08+00:00

In my app I have a user model, school model, course model, and a

  • 0

In my app I have a user model, school model, course model, and a syllabus model. A user or school could create courses which I have set through a polymorphic association (course belongs_to :hostable, and school/user has_many :courses, as: :hostable) , and a course has_one syllabus. My question is how to configure the routes for the nested course model which also has a syllabus model nested within it.

resources :users do
  resources :courses do
   resources :syllabus
  end 
    member do
    put :enroll
   end
  end

 resources :schools do
  resources :courses do 
   resources :syllabuses
  end
   member do
  put :apply, :enroll
  end
end

So users can enroll in courses by clicking a button on the course page, in my courses controller I have:

def enroll
  @course = Course.find(params[:id])
  current_user.coursegroups.create(host_course_id: @course.id, role: 'applicant')
  respond_with @course
end

So, is this the correct way to configure my routes?

  • 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-06T14:21:10+00:00Added an answer on June 6, 2026 at 2:21 pm

    Stefan’s right that you should be careful about nesting resources more than one level deep, but I personally don’t find nesting unmanageable until two levels. Either way, it’s just a personal preference.

    For your routes, the one thing that immediately jumps out at me is that nesting everything inside users and schools isn’t necessary, since it sounds like you’ll be logging in as a user or school. Routes with the logged-in user in them are very difficult to manage: users can’t share them and they don’t really reflect the state of the specified resource. For example:

    /users/1/courses/14/syllabus/3
    

    Theoretically, courses/14/syllabus/3 should work the same for every logged-in user, but anyone trying to share a link to this would need to include their own user ID number first, which is somewhat silly. Instead structure your routes like so:

    resource :sessions
    resources :courses do
      resources :syllabus
      member do
        put :apply, :enroll
      end
    end
    

    In your session, allow either a user or school to log in, and vary what they see in the views (and what resources they’re allowed to access) based on who’s logged in using something like CanCan. Now your routes will reflect the actual resource (/courses/14/syllabus/3) correctly.

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

Sidebar

Related Questions

In my rails app I have user, school, and course models. I have set
I have a User model in my app, which I would like to store
In my app, I have a User model, which includes a number of attributes
I'm building an app in Rails 3. I currently have a user model which
I have my own User model in app engine, which should have a property
I have a Rails 3.1 app with a User model and a Venue model.
I have a Rails app, with 2 models : a User model and a
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I have a data model object User . My app also has some other
In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User

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.