best_in_place 嵌套属性内联编辑抛出“204 无内容”错误
best_in_place nested attribute inline edit throws "204 No Content" error
我正在使用 Best In Place Gem 对具有 Storeorder 嵌套属性的 table 任务进行内联编辑,但是当我尝试使用 中提供的说明,我收到 204 无内容错误。我想知道这是否与 'Storeorder Load' 发生之前开始的第一笔交易有关?在所有非嵌套 BIP 更新中,它在第一个 "begin transaction" 调用中执行更新,而此处它仍在加载 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 在参数中传递。
我正在使用 Best In Place Gem 对具有 Storeorder 嵌套属性的 table 任务进行内联编辑,但是当我尝试使用
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 在参数中传递。