I'm combining two models in my controller, and trying to print them in a similar fashion, but I'd like to do an if
statement in an each
loop to distinguish one model from the other. My models are comments and likes.
In the controller:
@items = (@user.likes + @user.comments).sort{|a,b| a.created_at <=> b.created_at }
In my view:
<%= @items.each do |item| %>
<% item.name %>
<% end %>
I need an if
statement to say IF comment
or IF like
in the each
loop. I've been drawing a blank on the situation.