简体   繁体   中英

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,

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

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. Bottom line: I don't know how to refresh more than 1 partial from this action.

你可以在create.js中渲染局部

$("#some_div_id").empty().html("<%=escape_javascript(render('layouts/notification'))%>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM