问题描述
我正在使用Stream Rails构建具有供稿的应用。 user
有一些page
,其他用户可以关注。为此,我创建了一个page
供稿组。这是我的Post
模型-
class Post < ApplicationRecord
belongs_to :page
belongs_to :author,class_name: "User"
has_one :post_item,inverse_of: :post
accepts_nested_attributes_for :post_item
include StreamRails::Activity
as_activity
def activity_object
self.post_item
end
def activity_actor
self.author
end
end
但是,帖子转到用户的供稿。如何将其转到page
供稿组?我浏览了github代码,我想必须重写activity_owner_Feed
吗?但我也希望作者列出他们创建的所有帖子。因此,帖子也必须位于user
供稿中。
这是我的控制器中的相应代码-
# this method creates the post
# This puts the post in user Feed
# I also want to add the post to page Feed
def create
@post = current_user.posts.build post_params
@post.save
render json: { success: true }
end
# show all posts of a user
def show
Feed = StreamRails.Feed_manager.get_user_Feed(current_user.id)
enricher = StreamRails::Enrich.new
results = Feed.get()['results']
@activities = enricher.enrich_activities(results)
render json: { activity: @activities }
end
对应路线-
post 'post/create'
post 'post/show'
解决方法
您需要覆盖activity_notify
并返回一组供稿,以进行通知。
它将翻译为to
target in the generated activity。