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