0
我的應用程序有帖子,有評論。這是我想要的功能:用戶在他創建的帖子上看到評論活動,並且評論者在他評論的帖子上看到評論活動。如何使用Rails 4中的Public Activity gem來通知涉及帖子評論帖子的每個用戶?
我的模型:
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :course
has_many :comments, dependent: :destroy
end
class Comment < ActiveRecord::Base
include PublicActivity::Model
tracked except: :update, owner: ->(controller, model) { controller && controller.current_user }
belongs_to :post
belongs_to :user
end
而且活動控制器:
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
而且活動指數的看法:
<% @activities.each do |activity| %>
<div class="activity">
<%= link_to activity.owner.username, activity.owner if activity.owner %>
added comment to <%= link_to activity.trackable.post.title, activity.trackable.post %>
</div>
<% end %>
謝謝!