我尝试制作通知系统并有问题
我需要通过以下方式向视图发布通知: track_activity.js.erb
<% publish_to "/notifications/new" do %>
$("#activity").append("<%= j render(@activity) %>");
<% end %>
和我的带有操作跟踪活动的application_controller
def track_activity(user, trackable, action = params[:action], author = current_user)
@activity = Activity.create! user: user, trackable: trackable, action: action, author: author
end
每当用户创建类似这样的内容时,我都会使用此方法
comment_controller.rb
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params)
@comment.user = current_user
if @comment.save
track_activity @post.user, @comment
redirect_to post_path @post
else
render 'new'
end
end
每次rails调用track_activity动作时如何附加track_activity.js.erb? track_activity动作中的respond_to没有帮助