I understand how STI works, in that I have say a Post model that
contains posts on a forum and several sub-posts like
'ordinaryUserPost' and 'adminUserPost' etc.

Now, I want to define the same method in each of the sub-posts, but
the method would do something different in each case, eg

class Post < ActiveRecord::Base
end

class AdminUserPost < Post
  def background_color
    'rockstar red'
  end
end

class ordinaryUserPost < Post
  def background_color
    'pale blue'
  end
end

(yes its a silly example).  Now in my thread controller I do Post.find
(:all) and it gives me a list of posts I need to render, but they are
'Post' objects, not AdminUserPost or OrdinaryUserPost - so I cannot
just get my background_color method!  I would have to do a find on
each type of user post separately ...

Is there anyway I can do:

Post.find(:all)

And in the resultant array get a list of AdminUserPost and
OrdinaryUserPost objects instead of Post objects?

Thanks,

Stephen.
--~--~---------~--~----~------------~-------~--~----~
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