[英]Rails: How to render more than one partial from one controller's action?
I'm creating comments and I use create.js
file that contains an ajax call to add comments, 我正在创建注释,我使用包含ajax调用的create.js
文件来添加注释,
Now I'm adding notification into a partial, I want the notification section to refresh at the same time when the comment is added, 现在我将通知添加到局部,我希望通知部分在添加注释的同时刷新,
I'm trying to do this but it doesn't work, I was wondering if there would be a way around it: 我正在尝试这样做,但它不起作用,我想知道是否会有办法解决它:
inside def create
action 内部def create
动作
if @comment.save
track_activity @comment
#refresh_dom_with_partial('div#comments_container', 'comments')
respond_to do |format|
format.js { @comments = @commentable.user_comments.order(:created_at) }
format.html #{ redirect_to @commentable }
render :partial => "layouts/notification"
end
else
render :new
end
the render :partial => "layouts/notification"
is kind of breaking the comment Ajax call as well. render :partial => "layouts/notification"
也是一种打破Ajax调用的注释。 Bottom line: I don't know how to refresh more than 1 partial from this action. 结论:我不知道如何从这个动作中刷新超过1个部分。
你可以在create.js中渲染局部
$("#some_div_id").empty().html("<%=escape_javascript(render('layouts/notification'))%>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.