0

さて、私は次の作成アクションを持っています

  #posts_controller, nested resource under discussions
  def create
    @post = Post.new(params[:post])
    @post.user = current_user
    @post.discussion = Discussion.find(params[:discussion_id])
    respond_to do |format|
      if @post.save!
        format.js
        format.html { redirect_to discussion_posts_path(@post.discussion), notice: 'Post was successfully created.' }
      else
        format.html { render :action => "new" }
      end
    end
  end

次の形式から外れます

#index.html.erb#quick_reply
<%= simple_form_for [@discussion, @post], :remote => true do |f| %>
  <%= f.input :body, :input_html => {:class => 'span12 short_text_area' } %>
  <%= f.submit 'Post Reply', :class => 'btn-primary' %>
<% end %>

このコーヒースクリプトを開始する

#create.js.coffee
$("#discussion_posts_table").append("<%= escape_javascript(render(@post)) %>");
$("#post_body").val("");

フォームから取り出す:remote => trueと、すべてがうまく機能しますが、フォームに入れると、1 つではなく 2 つのモデル オブジェクトが作成されます。

ここで何が間違っている可能性がありますか?

4

1 に答える 1

0

結局のところ、問題は dev でアセットをプリコンパイルしていたことでした。つまり、すべてがそこに 2 回ありました。

于 2012-06-22T01:20:16.970 に答える