I have one feed in static_page home.html.erb
that I'm trying to combine two renders
Here's what I mean:
First this is my controller
class StaticPagesController < ApplicationController
def home
if signed_in?
@micropost = current_user.microposts.build
@activities = PublicActivity::Activity.order("created_at desc").paginate(page: params[:page])
@feed_items = current_user.feed.paginate(page: params[:page])
else
redirect_to root_path
end
end
this is what I'm using inside the view
<%= render partial: 'shared/feed_item', collection: @feed_items %>
<%= will_paginate @feed_items %>
Here's the view shared/feed_item
for @feed_items
that is being rendered in
I want to join @activities
into @feed_items
so that they both display in the same list in descending order
<li id="<%= feed_item.id %>">
<br>
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<%= link_to feed_item.user.name, feed_item.user %>
<span class="textname">shared this</span><span class="timestamp"> <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
</li>
Can I use some form of if-else to integrate this view for @activities
below into the above code to make them become a part of one list?
<li>
<% if activity.trackable_type == "Micropost" %>
<span class="user"><%= link_to activity.owner.name, activity.owner if activity.owner %></span><span class="textname"> posted this</span><span class="timestamp"> <%= time_ago_in_words(activity.created_at) %> ago.
</span>
<% else %>
<span class="user"><%= link_to activity.owner.name, activity.owner if activity.owner %></span><span class="textname"> made a comment</span><span class="timestamp"> <%= time_ago_in_words(activity.created_at) %> ago.
</span>
<% end %>
</li>
the full _item.html.erb that I created by joining _activity.html.erb and _feed_items.html.erb
<li>
<% if item.class == PublicActivity::Activity %>
<% if activity.trackable_type == "Post" %>
<%= link_to activity.owner.name, activity.owner if activity.owner %><span class="textname"> posted </span><span class="timestamp"> <%= time_ago_in_words(activity.created_at) %> ago.
</span>
<% else %>
<%= link_to activity.owner.name, activity.owner if activity.owner %><span class="textname"> made a comment</span><span class="timestamp"> <%= time_ago_in_words(activity.created_at) %> ago.
</span>
<% end %>
<% else %>
<br>
<span class="user">
<%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="textname">shared this</span><span class="timestamp"> <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
</li>
<% end %>