我使用Public_Activity寶石以顯示操作列表正在網站上進行。我在主頁上已經有了一個主要Feed,但我還想包括使用該寶石進行跟蹤的所有活動。將兩個部分合併爲一個(導軌3),我是這樣做的嗎?
這裏就是我想要的控制器
class StaticPagesController < ApplicationController
def home
if signed_in?
@micropost = current_user.microposts.build
@feed_activities = PublicActivity::Activity.order("created_at desc")
@feed_posts = current_user.feed.without_review.paginate(page: params[:page])
@feed_items = @feed_posts + @feed_activities
end
end
然後在我的觀點裏做的,這就是我正在努力把它
<% if @feed_items.any? %>
<ol class="microposts">
<%= render partial: 'shared/feed_item', collection: @feed_items %>
</ol>
<%= will_paginate @feed_items %>
<% end %>
的_feed_item.html上述被稱爲是
<li id="<%= feed_item.id %>">
<br>
<% if @feed_activities? %>
<%= link_to activity.owner.name, activity.owner if activity.owner %> has posted
<% else %>
<div class ="gravatarhome"><%= link_to gravatar_for(feed_item.user), feed_item.user %></div>
<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>
<div class="FeedContent"><%= truncate(feed_item.content, :length=>150, :omission=>' ...(continued)') %>
<% if current_user?(feed_item.user) %>
<%= link_to "delete", feed_item, method: :delete,
confirm: "You sure?",
title: feed_item.content %>
<% end %><br>
<% end %>
</li>
不過,我得到這個錯誤
NameError in Static_pages#home
Showing C:/app/views/shared/_feed_item.html.erb where line #5 raised:
undefined local variable or method `activity' for #<#<Class:0x6ef3b98>:0x60d50d8>
人知道是否有更好的方法來做到這一點,在活動變量需要被定義爲得到這個工作?
更新:這是我的application_controller使用寶石
class ApplicationController < ActionController::Base
include PublicActivity::StoreController
現在我得到未定義的方法'老闆」 ......你知道我需要定義嗎? – syk 2013-04-29 04:42:36
首先讓我知道,你想循環什麼,並有任何方法命名所有者或與所有者的關聯。 – 2013-04-29 04:46:25
這裏,feed_item是通過@feed_items集合變量循環對象你已經在渲染部分通過。它沒有任何方法或協會命名所有者。所以它給錯誤未定義的方法'所有者'。 – 2013-04-29 04:58:39