best_in_place嵌套属性内联编辑引发"204 No Content"错误



我正在使用Best In Place Gem对具有Storeorder嵌套属性的Task表进行内联编辑,但当我尝试使用本文中提供的说明编辑Storeorder属性时,我遇到了204 No Content错误。我想知道这是否与"Storeorder Load"发生之前开始的第一个事务有关?在所有非嵌套的BIP更新中,它在第一个"开始事务"调用中执行UPDATE,而在这里它仍然加载Storeorder。据我所知,这些参数是100%正确的。参见代码,

Started PUT "/tasks/3" for 104.200.151.54 at 2017-02-05 18:08:24 +0000
Processing by TasksController#update as JSON
Parameters: {"task"=>{"storeorder_attributes"=>{"id"=>"3", "activity"=>"Shipped"}}, "authenticity_token"=>"D2c3ddoIC220rkPE5i7U+EGiwSrdCq7s8vdFY8VEQTaTMqetuBo8SJX9+Wabl+Bh6A6d49Pt/Omp4E/nq/udQA==", "id"=>"3"}
User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 1], ["LIMIT", 1]]
Task Load (0.2ms)  SELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?  [["id", 3], ["LIMIT", 1]]
CACHE (0.0ms)  SELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?  [["id", 3], ["LIMIT", 1]]
(0.1ms)  begin transaction
Storeorder Load (0.2ms)  SELECT  "storeorders".* FROM "storeorders" WHERE "storeorders"."task_id" = ? LIMIT ?  [["task_id", 3], ["LIMIT", 1]]
(0.1ms)  commit transaction
(0.1ms)  begin transaction
(0.1ms)  commit transaction
Completed 204 No Content in 10ms (ActiveRecord: 1.0ms)

tasks_controller.rb->

class TasksController < ApplicationController
before_action :set_task, only: [:show, :edit, :update, :destroy]
def update
@task = Task.find(params[:id])
respond_to do |format|
if @task.update(task_params)
format.html { redirect_to @task, notice: 'Task was successfully updated.' }
format.json { respond_with_bip(@task) }
else
format.html { render :edit }
format.json { respond_with_bip(@task) }
end
end
end
private
def set_task
@task = Task.find(params[:id])
end
def task_params
params.require(:task).permit!
end
end

task.rb->

class Task < ApplicationRecord
has_one :storeorder, :dependent => :destroy
accepts_nested_attributes_for :storeorder, :reject_if => lambda { |a| a[:store_id].blank? }, :allow_destroy => true
end

storeorder.rb-->

class Storeorder < ApplicationRecord
belongs_to :task
end

dashboard.html.erb-->

<td><%= best_in_place task.storeorder, :activity, 
url: task_path(task.id), 
param: "task[storeorder_attributes][id]=#{task.storeorder.id}&task[storeorder_attributes]", 
as: :select, 
collection: [["Pending Shipment", "Pending Shipment"], ["Shipped", "Shipped"], ["Cancelled", "Cancelled"], ["Pending Further Action", "Pending Further Action"]], %>
</td>

内部HTML代码-->

<span 
data-bip-type="select" 
data-bip-attribute="activity" 
data-bip-collection="[["Pending Shipment","Pending Shipment"],["Shipped","Shipped"],["Cancelled","Cancelled"],["Pending Further Action","Pending Further Action"]]" 
data-bip-inner-class="form-control" 
data-bip-object="task[storeorder_attributes][id]=3&task[storeorder_attributes]" 
data-bip-original-content="Pending Shipment" 
data-bip-skip-blur="false" 
data-bip-url="/tasks/3" 
data-bip-value="Shipped" 
class="best_in_place form-control" 
id="best_in_place_storeorder_3_activity">
Shipped
</span>

我看不出我可能遗漏了什么导致了这个错误。必须允许我进行内联编辑以保持工作流的一致性,否则我对其他建议持开放态度,因为我知道BIP默认情况下在其范围内没有嵌套属性编辑。

:reject_if => lambda { |a| a[:store_id].blank? }没有看到任何store_id在params中传递。

相关内容

最新更新