具有配置文件模型的Public_activity gem

时间:2016-09-01 19:29:00

标签: ruby-on-rails ruby-on-rails-4 public-activity

我正在使用public_activity gem。我有一个帖子模型,用户模型(用设计生成)和一个配置文件模型。

使用public_activity gem我可以在创建,编辑或删除Post时显示新闻Feed,但我需要一种方法来显示与Post相关联的用户名,用户名称存储在Profile模型中,而不是User生成的devise模型中。以下是我到目前为止的情况:

用户模型:

class User < ActiveRecord::Base
  has_many :posts
  has_one :profile
end

发布模型:

class Post < ActiveRecord::Base
  belongs_to :user
  include PublicActivity::Model
  tracked owner: Proc.new{ |controller, model| controller.current_user }
end

个人资料模型:

class Profile < ActiveRecord::Base
  belongs_to :user
end

我为示例views/public_activity/post/_create.html.erb

设置了标准视图
<li class="list-group-item">
  <% if a.trackable %>
    <%= a.trackable.name %> was created.
  <% else %>
    An article that is currently deleted was added.
  <% end %>
</li>

我正在尝试这样的事情:

<div class="activities">
  <% @activities.each do |activity| %>
  <div class="activity">
    <%= activity.owner.profile.name %>
    <%= render_activities(@activities) %>
  </div>
  <% end %>
</div>

但这不起作用,错误是:

undefined method `profile' for nil:NilClass

0 个答案:

没有答案