1

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

使用 public_activity gem,我可以让新闻提要显示Post创建、编辑或删除 a 的时间,但我需要一种方法来显示与 关联的Post用户名,用户名存储在Profile模型中,而不是Userdevise. 这是我到目前为止所拥有的:

用户型号:

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
4

0 回答 0