我想推送一些websockets,当调用路由时,通常会从jbuilder视图返回的内容,但我不能在一个动作中调用render两次:
def
...
@resource_receivers = "#{@resource.model_name.singular.capitalize}Receiver".constantize.where("#{@resource.model_name.singular}_id": @resource)
@resource_receivers.each do |resource_receiver|
resource_receiver.create_activity :sent, owner: @current_user, recipient: resource_receiver.receiver
end
to_return = render 'api/received/show'
Pusher.trigger('resources', 'resource.received', JSON.parse(to_return.first))
return render :task
end
我该如何解决这个问题?或者一般来说,我想在我的应用程序中的任何其他地方返回通常从jbuilder返回的内容,例如,如果我想重构这个以便有一个推送给用户的方法