Question

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.

Was it helpful?

Solution

you can render the partial inside create.js

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top