UJS Create Action正在发布两篇帖子

时间:2012-06-13 03:19:58

标签: ruby-on-rails coffeescript ujs

好的,我有以下创建动作

  #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 %>

开始这个coffeescript

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

如果我从表单中取出:remote => true,一切都很好,但是把它放进去会产生两个模型对象而不是一个。

知道我在这里做错了什么吗?

1 个答案:

答案 0 :(得分:0)

事实证明,问题在于我在dev中预编译了资产,这意味着所有内容都在那里。

相关问题