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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.