내 앱에 댓글이있는 게시물이 있습니다. 이것은 내가 원했던 기능입니다. 사용자가 자신이 작성한 게시물에 대한 주석 활동을보고 주석 작성자가 주석 처리 한 게시물에 대한 주석 활동을 봅니다.레일즈 4의 퍼블릭 액티비티 젬을 사용하여 게시물의 코멘트 스레드에 관련된 모든 사용자에게 어떻게 알릴 수 있습니까?
내 모델 :
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 %>
감사합니다!