How can I maintain DRY code on polymorphic controllers and views? For
example, I am building an app where users have many posts and at the
same time a group can have many posts and a category can be related to
many posts (post belongs to a user, category and a group).
So what happens then to the posts_controller? How can I know for
example if I want to show the posts for a group, the posts of a
specific user or category?
Someone could tell me to do something like this:
@posts = Post.find(:all, :conditions => ["group_id = ?,
@posts = Post.find(:all, :conditions => ["user_id = ?,
@posts = Post.find(:all, :conditions => ["category_id = ?,
But then again this code will be unsustainable in the future when more
routes are added (ifs block will be hell). And when I take into
account that the views and links should render differently for each
case makes it worst.
What's the best solution for this? Any suggestions or guidelines are