我正在使用 PublicActivity ruby gem,并且收到此错误消息
这发生在里面/views/activities/_index.html.erb
<li>
<% if activity.trackable_type == "Micropost" %>
<%= link_to activity.owner.name, activity.owner if activity.owner %> posted
<% else %>
<%= link_to activity.owner.name, activity.owner if activity.owner %> made a comment on <%= link_to activity.recipient_id %>
<% end %>
</li>
但是,当我包含这一行时,它工作正常
<li>
<% @activities.each do |activity| %>
<% if activity.trackable_type == "Micropost" %>
<%= link_to activity.owner.name, activity.owner if activity.owner %> posted
<% else %>
<%= link_to activity.owner.name, activity.owner if activity.owner %> made a comment on <%= link_to activity.recipient_id %>
<% end %>
<% end %>
</li>
我在<% @activities.each do |activity| %>
上面加了。它可以正常工作,但问题是,在视图中,活动在同一个列表中重复。
这是activities/_index.html.erb
被调用的地方
我的views\shared\_feed.html.erb
<%= render partial: 'activities/index', collection: @activities %>
我的活动控制器
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
@activity = PublicActivity::Activity.order("created_at desc")
end
end