【问题标题】:UJS Create Action is making two postsUJS Create Action 正在发布两篇文章
【发布时间】:2012-06-13 03:19:58
【问题描述】:

好的,我有以下创建操作

  #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 =&gt; true 从表单中取出,一切都会很好,但将它放入会生成两个模型对象而不是一个。

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

【问题讨论】:

标签: ruby-on-rails coffeescript ujs


【解决方案1】:

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

【讨论】:

  • 非常熟悉 - 不久前也遇到过这种情况:)
猜你喜欢
  • 2017-01-04
  • 1970-01-01
  • 2018-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多