Topic: RoR Association Question

Hi,
Lets say that I have 3 models: Student, Exam, Questions
Student has_one :Exam
Exam has_many :Questions

Should I nest the Questions under Exam or should I put it under Student?
If I nest the Questions under Exam (2 nests) how do I create the object, if I nest it under Student it is
@student.find(1)
@question = @student.build_question

Also I keep getting confuse over if the method should be in the controller vs inside the model.
Sorry about asking so much questions, I tried borrowing many books but they confuse me futher, I am unable to fully gasp the concept like in C/C++.

Re: RoR Association Question

You can use 'accepts_nested_attributes_for' AR method , see
Rails API for more details as well as Rails casts, part 1 and 2 on how to use nested forms:
http://railscasts.com/episodes/196-nest … orm-part-1
http://railscasts.com/episodes/197-nest … orm-part-2

Second, it is preferred to define models-specific methods inside models classes (fat models vs slim controllers).

Last edited by Javix (2012-06-11 06:28:55)