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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:24:31+00:00 2026-06-06T02:24:31+00:00

I’m in the process of trying to develop my first rails application and before

  • 0

I’m in the process of trying to develop my first rails application and before I jump off into actually implementing my ideas, I was hoping I could get some help with my association planning.

My application is going to be an educational tool and I have some basic functionality that I need to implement. I want to have students that can register for and create courses. Within these courses, there will be one user who is the teacher and the rest are students. Within the course will be assignments that the teacher creates and that users are required to make a submission for. These are the basics. Eventually I want to add more functionality but as of now I just need the foundations set.

Here are my ideas so far on what the associations should look like:

class User < ActiveRecord::Base
    has_many :enrollments
    has_many :courses, :through => :enrollments
end

class Course < ActiveRecord::Base
    has_many :enrollments
    has_many :users, :through => :enrollments
end

class Enrollment < ActiveRecord::Base
    belongs_to :user     # foreign key - user_id
    belongs_to :course   # foreign key - course_id
end

However, I’m running into my wall of inexperience at the moment with how to appropriately handle the rest of the associations at this point. I could probably hack out something, but I’d prefer to do it as best as I can the first time.

How do I handle the associations related to assignments and submissions? Presumably a student’s submission should belong_to them, but it is also specifically related to an assignment within the class. Assignments originate within a course, but are also closely tied to the user.

Finally, what’s the best way to handle the relationships between a user and the class they create? A user creates a course. Does that course belong_to them? Should I just add a column to the course’s table for storing the creator’s id? Etc.

Thanks for the help.

  • 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-06T02:24:34+00:00Added an answer on June 6, 2026 at 2:24 am

    Suggestion:
    You might want to separate out your Teacher and Student models, since you’re very likely to have different actions associated with each (and while they share some attributes, they really are different entities in your model, for example, you likely want just one teacher teaching in a course.)
    You could derive both the Teacher model and the Student model from a User model that has the shared attributes and authentication.

    Now to your questions:

    If you’d like to keep the student that created the course associated, creator_id is the way I’d go. (If a teacher can create a course too, deriving Student and Teacher from a shared User model would help)

    Assignments and Submissions:
    You’ve pretty much defined it in words. Here is the code.
    [If different students within a course could get different assignments, only then do you want to build a direct association between Student and Assignment, otherwise, use a through association]

    class User < ActiveRecord::Base
        has_many :enrollments
        has_many :courses, :through => :enrollments
        has_many :assignments, :through => :courses
        has_many :submissions
    end
    
    class Course < ActiveRecord::Base
        has_many :enrollments
        has_many :users, :through => :enrollments
        has_many :assignments
    end
    
    class Enrollment < ActiveRecord::Base
        belongs_to :user     # foreign key - user_id
        belongs_to :course   # foreign key - course_id
    end
    
    class Assignment < ActiveRecord::Base
        belongs_to :course
        has_many :submissions
    end
    
    class Submission < ActiveRecord::Base
        belongs_to :assignment
        belongs_to :user
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.