我正在使用'public_activity'gem来创建活动Feed。我跟着this tutorial
本教程向您介绍如何为关注某些人的用户创建活动Feed。
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.followed_user_ids, owner_type: "User")
end
...
如何添加current_user的id,以便在索引页面上看到他跟随的人加上他自己的活动?
答案 0 :(得分:1)
您可以创建另一个变量并将其放在索引视图中的@activities变量之前吗?
这样的东西就是控制器:
class ActivitiesController < ApplicationController
def index
@activities_current_user = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.id, owner_type: "User")
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.followed_user_ids, owner_type: "User")
end
然后在视图中:
<% @activities_current_user.each do |activity| %>
<div class="activity">
<%= link_to activity.owner.name, activity.owner if activity.owner %>
<%= render_activity activity %>
</div>
<% end %>
<% @activities.each do |activity| %>
<div class="activity">
<%= link_to activity.owner.name, activity.owner if activity.owner %>
<%= render_activity activity %>
</div>
<% end %>