My comment app works ,but the only problem is whenever i refresh the page the comments disappear.In the log it shows the body is inserted in the comments table(it is saved).What am i doing wrong here?Any help will be appreciated.Thank you in advance.
View#show
<div id="comments"></div>
<%= form_for :comment,:remote => true,:url=> {:controller=>"comments",:action=>"create"},:html => { :id => 'new-comment'} do |f| %>
<%= f.text_area(:body) %>
<div class="errors"></div>
<%= f.submit "post" %>
<% end %>
Comment controller
class CommentsController < ApplicationController
respond_to :js
def create
@deal=Deal.find(1)
@comment =@deal.comments.build(params[:comment])
@comment.save
respond_with( @comment, :layout => !request.xhr? )
end
def show
@comment=Comment.all
@deal=Deal.find(1)
@comment=@deal.comments
end
end
create.js.erb
$('#comments').append("escape_javascript(@comment.body)");