私のコメントアプリは動作しますが、唯一の問題は、ページを更新するたびにコメントが消えることです。ログには、コメントテーブルに本文が挿入されていることが示されています(保存されています)。 。前もって感謝します。
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 %>
コメントコントローラー
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)");