2013-04-29 31 views
0

我使用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 

回答

0

错误都表示这个问题,Rails不知道哪些行为是指。

无论你有活性装入控制器,或与之关联feed_item 或者不轨不知道哪些活动是指

0

活动是在这部分定义的变量,所以它会给错误。 如果你想通过循环收集的所有活动,那么你必须通过变量集合在渲染部分,并使用部分名称,像这样的呼吁:

<%= link_to feed_item.owner.name, feed_item.owner if feed_item.owner %> has posted 

在您的部分由feed_item更换活动。它会解决你的问题。

+0

现在我得到未定义的方法'老板” ......你知道我需要定义吗? – syk 2013-04-29 04:42:36

+0

首先让我知道,你想循环什么,并有任何方法命名所有者或与所有者的关联。 – 2013-04-29 04:46:25

+0

这里,feed_item是通过@feed_items集合变量循环对象你已经在渲染部分通过。它没有任何方法或协会命名所有者。所以它给错误未定义的方法'所有者'。 – 2013-04-29 04:58:39

相关问题