I'm somewhat new to Ruby and Rails and I'm trying to figure out how to model the following relation using Ruby's dynamic language features....
The domain is essentially a questionnaire, so I have Users, Questions, and Answers.
A User has an id and a name. An Answer has a userid and a questionid and a value property which is the user's answer to that particular question.
Each question has a unique 'Code', so for example, a question might be, "What is your favourite color?", and code would be "fav_color".
If I have a User instance, I want to be able to do: user.fav_color to get/set this answer.
I figure I could try and user method_missing and then make a finder call like in this example: http://rpheath.com/posts/241-how-to-use-method-missing
Or can I dynamically add properties to a class at run-time like here:
Ruby - dynamically add property to class (at runtime)
But I need to read / write to the database....simply storing these dynamic properties in an instance variable is no good for me.
Any help would be much appreciated...or advice on a better way to approach this problem :)