Ruby on Rails Applying Model to Two Other Models

20 views
Skip to first unread message

Jacob Grishey

unread,
Jan 20, 2015, 5:48:43 PM1/20/15
to rubyonra...@googlegroups.com
Hi, I know this is probably a basic question but I am relatively new to Ruby on Rails.

I have a website in which I have three models: courses, students, and works. The website is supposed to be a grade keeper. A course has many works, like a test. You can add a work to a course, but I want that work to be distributed as single works to each student in that course as well. Does anyone know how I would be able to do this? 

Thank you in advance,

Jacob Grishey

Colin Law

unread,
Jan 21, 2015, 5:04:19 AM1/21/15
to rubyonra...@googlegroups.com
If I understand correctly is it just that you want
Student has many works
Work belongs to student

Or possibly you need a has_and_belongs_to_many between them.

If not then please explain the problem more carefully. In particular
I don't know what you mean by 'distributed as single works'.

Have you already worked right through a good tutorial such as
railstutorial.org (which is free to use online)? If not then I
suggest you do that before anything else, it will give you a good
grounding in rails.

Colin

>
> Thank you in advance,
>
> Jacob Grishey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/80495e07-97d8-4ff3-94da-a4fbebea3738%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Jan 21, 2015, 12:12:52 PM1/21/15
to rubyonra...@googlegroups.com

On Jan 20, 2015, at 5:48 PM, Jacob Grishey <jgri...@gmail.com> wrote:

> Hi, I know this is probably a basic question but I am relatively new to Ruby on Rails.
>
> I have a website in which I have three models: courses, students, and works. The website is supposed to be a grade keeper. A course has many works, like a test. You can add a work to a course, but I want that work to be distributed as single works to each student in that course as well. Does anyone know how I would be able to do this?
>

This feels like it's lacking another model. I did a system where there were quizzes after a medical Continuing Education presentation, and there was the following setup:

User (has_many examinations)
Examination (belongs_to user, belongs_to test) [also stores the individual's answers to each question]
Test (has_many examinations)

I won't get into the questions and answers here, but this should give you a possible direction. The idea is that a Test is a template -- the mimeograph master if you go back that far. There are many examinations derived from that test, and each examination is referencing a single user and a single test (master). How that exam gets filled out is unique to the user, and I think that's the missing model you are looking for.

Walter

> Thank you in advance,
>
> Jacob Grishey
>
Reply all
Reply to author
Forward
0 new messages