2013-03-12 21 views
0

我试图在我的Rails应用程序中实现公共活动宝石。我以优异的Railscast插曲(http://railscasts.com/episodes/406-public-activity)沿以下,但是当我本地主机上运行我碰到以下错误:3000 /活动:未定义的方法错误与Rails中的公共活动宝石

NoMethodError在#

活动#指数 未定义的方法'内容”

错误显示,问题出在视图/活动/ index.html.erb文件:

<% @activities.each do |activity| %> 
    <div class ="activity"> 
     <%= link_to activity.owner.content, activity.owner if activity.owner %> 
      <%= render_activity activity %> 
     </div> 
     <% end %> 

它似乎不喜欢在第三行的“的link_to activity.owner.content”位。

活动控制器:

class ActivitiesController < ApplicationController 
    def index 
    @activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.followed_users.all, owner_type: "User") 
    end 
end 

内容是在我的职位表中的列。我试图追踪/显示特定用户可能遵循的用户活动。我的问题是否存在于上述其中一个文件中,或者是其他地方的问题?

如果有帮助,如果我

<% @activities.each do |activity| %> 
    <%= activity.inspect %> 
<% end %> 

更换index.html.erb视图我可以看到没有错误显示在页面上的原始数据。一旦我用前面提到的新代码替换检查代码,就会出现错误。任何帮助将不胜感激。

附加信息:我正在使用Devise进行用户身份验证,并且正在使用Michael Hartl的Railstutorial示例应用程序中显示的跟随者系统。

谢谢!

回答

0

您是否拥有车型有内容属性?

的railcast说

<%= link_to activity.owner**.name**, activity.owner if activity.owner %> 

,而不是

<%= link_to activity.owner.content, activity.owner if activity.owner %> 
+0

感谢您的答复。没有所有者模型,所以这是我陷入困境的一部分。他使用.name是因为他的配方模型中有一个name属性,所以我想我可以使用我的post模型中的content属性进行切换。 – winston 2013-03-12 11:09:28

+0

你使用的是设计。这将创建用户模型,该模型将current_user作为owner_id作为用户。 – RoRRe 2013-03-12 13:39:54

+0

是的,我正在使用设计。我想为current_user跟随的用户显示活动,因此我将owner_id设置为current_user.followed_users。我是否需要将其更改为current_user? – winston 2013-03-12 14:45:18

相关问题