If you modeled the database as single table inheritance (STI) then
this is not that hard. You do A.find(:all) to get the objects and
some will be Bs rather than As.
In your view you can test for whether they are A or B to present the
right information. Alternatively you can ask them for some piece of
information that you use to form the name of a partial that will be
specific to that type such as _A_row and _B_row with render :partial
=> "#{obj.class.name}_row" or something like that.
Michael
On May 26, 7:30 pm, Magicloud
<magicloud.magiclo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have some models like this:
> ---
> class A < ActiveRecord; end
> class B < A; end
> ---
> Now I want to use an action ''list'' to list out both As
and Bs, and I
> hope every item shows depending on it model. Like this:
> ---
> A1: name=xx, age=yy
> B1: name=mm, age=uu, sex=male
> A2: name=aa, age=bb
> ---
> I think this is just a question on polymorphism, right?
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---