与ajax关联的update_attributes确实插入而不是更新

时间:2016-03-21 13:30:15

标签: ruby-on-rails

我使用ajax将演示文稿管理到Subscription模型中。每个订阅可以有很多演示文稿。演示文稿在订阅表单中作为单独的表单存在,并使用remote=true来执行更新。

当我这样做时:insert, reload page, insert什么都不会出错。但是,当我执行:insert, insert时,它将以三个不同的记录结束,而不是两个记录正在更新。

javascript调用的代码是:

def update_properties
  Subscription.skip_callback(:save, :after, :notify_observer)

  if !subscription_params[:presentations_attributes].nil?
    returns = @subscription.update_attributes(presentations_attributes: subscription_params[:presentations_attributes])
  end

  if returns
    respond_to do |format|
      format.html
      format.js
    end
  end
end

@subscription取自方法:

def set_subscription
  @subscription = Subscription.find(params[:id])
end

subscription_params方法:

def subscription_params
  params.require(:subscription).permit(:role, presentations_attributes: [:id, :title, :presentation_id, :_destroy, :subscription_id])
end

0 个答案:

没有答案