Daniel Bush wrote:
> 2009/4/29 Chris Hanks <[email protected]>
> 
>>   has_many :examples, :as => :sections
>> And get:
>> sections for each tutorial, also, to make sure they appear in the right
>> order.
>>
>> Does that make sense? I think single table inheritance might do this,
>> but I'm planning on using examples and questions for a bunch of other
>> things, so I don't think it would work that well. I'm thinking about
>> defining a whole new "section" model, and using that, but I don't know
>> yet.

I must be missing something here, but given that you have separate 
models [Tutorial, Question, Example] then what's wrong with:

Tutorial << ActiveRecord::Base
  has_many :questions
  has_many :example
end

Question <<  << ActiveRecord::Base
  belongs_to :tutoiral
end

Example << ActiveRecord::Base
  belongs_to :tutorial
end

Then given that Ruby is a duck typed language just put the questions and 
examples together in one array and as long as you stick to the common 
API for your ToC, or whatever it will just work:

toc = tutorial.questions.concat(tutorial.examples)

toc.each do |item|
  puts item.class
  puts item.name
end
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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