I made a commenting system that would comment under a micropost but the issue is that the whole page refreshes rather than just the comment section area like facebook does it. I think it may have to do with my create.js but I am not sure. Any suggestions will be much appreciated! Thank you!
This is my current js for the create.js:
$("#comments").html("<%= escape_javascript(render(:partial => @micropost.comments)) %>");
comment controller
class CommentsController < ApplicationController
def create
@micropost = Micropost.find(params[:micropost_id])
@comment = @micropost.comments.build(params[:comment])
@comment.user_id = current_user.id
@comment.save
respond_to do |format|
format.html
format.js
end
end
end
Comment Section
<div id='CommentContainer-<%= micropost.id%>' class='CommentContainer Condensed2'>
<div class='Comment'>
<%= render :partial => "comments/form", :locals => { :micropost => micropost } %>
</div>
<div id='comments'>
<%=render micropost.comments %>
</div>
</div>
You need to make sure that the comments form is being submitted remotely (
:remote => true) and that your comments section is equipped to handle the response from the server and that the form function responds to js/json