This could have been solved earlier. But I couldn't find a  solution.

Lets say I have an abstract base model called 'Question' and sub-
models like Mcq, TrueFalse and FillInTheBlank. Mcq and TrueFalse
models have a has_many relation with another model named 'Choice'
whereas FillInTheBlank model doesn't have this. So I have defined the
choice relation in Mcq and TrueFalse class. While instantiating the
Mcq and TrueFalse classes in my controllers I don't know which class
the instance is going to belong (all I know is it doesn't belong to
FillInTheBlank). So I call it like 'Question.find(params[:id])'. Due
to the 'type' column I get either an 'Mcq' instance or a 'TrueFalse'
instance. Perfect. But the code breaks down when I call choices method
on this new instance. It says "NoMethodError: undefined method
`choices' for #<Mcq:0x3046a84>"

However this problem doesn't come up if I call the find method on the
correct class i.e. Mcq.find() directly. But as I said earlier the
problem is I don't know whether the question is going to be a Mcq or a
TrueFalse.

One dirty solution I tried is to call find on the abstract class
(Question.find()), get value of 'type' attribute and issue another
find statement on the correct class (Mcq.find()). But even that didn't
solve the problem.

Has anybody faced this kind of a problem? Can someone point me in the
right direction?

Thanks much.
subbu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to