0

I have a collection of 3 types of objects, Posts, Products, and Content. I want to put all of these objects into a feed and order them by when they were created. I've done all that. The issue I'm having is I want to have a different partial for each item. How would I do that?

Here's the controller action getting all the objects:

 @stream = current_user.stream
Alex Smith
  • 385
  • 4
  • 21

1 Answers1

1

You can try something like this if each item has it own class:

@stream.each do |item|    
  render item
end

Or this if there is a field "kind" for the objects:

@stream.each do |item|    
  render item.kind
end

and create the following partials:

_post.html.erb
_product.html.erb
_content.html.erb

Just be sure that those files are on the correct view folder

Anezio Campos
  • 1,555
  • 1
  • 10
  • 18