我有一个带有呼叫的应用程序。每次通话都可以取消。当取消操作中的呼叫被取消时,我会呈现一个 cancel_form,它为用户提供取消选择的理由并利用更新操作来编写参数。
它运行良好,但是每当我使用它时,它都会清除我的 transfer_date 字段。参数显示设置了正确的 cancel_reason_id,然后将 transfer_date 设置为 NULL。我的代码中没有任何涉及 transfer_date 的内容,所以我很困惑。
这是params的代码和输出:
Params:
Processing by CallsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SoiMjWjeMFXXeiA9N8nNwfIQDa7pbB0YS9XkmKY6AuQ=", "call"=>{"cancel_reason_id"=>"1"}, "button"=>"", "id"=>"183"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 14 LIMIT 1
Call Load (0.3ms) SELECT "calls".* FROM "calls" WHERE "calls"."id" = $1 LIMIT 1 [["id", "183"]]
(0.1ms) BEGIN
(0.6ms) UPDATE "calls" SET "cancel_reason_id" = 1, "transfer_date" = NULL, "updated_at" = '2012-09-29 18:02:03.315975' WHERE "calls"."id" = 183
(1.9ms) COMMIT
CallsController 取消操作:
def cancel
@call = Call.find(params[:id])
attrs = {
call_status: 'cancel',
incharge_id: @call.units.first.incharge_id,
attendant_id: @call.units.first.attendant_id
}
attrs.merge!({ incharge2_id: @call.units.second.incharge_id, attendant2_id: @call.units.second.attendant_id }) if @call.units.count == 2
if @call.update_attributes(attrs)
@call.units.each do |unit|
CallMailer.cancel_call(unit.incharge, @call).deliver
CallMailer.cancel_call(unit.attendant, @call).deliver
end
render "cancel_form"
else
redirect_to calls_url, :error => "Whoops."
end
end
Cancel_form 视图
<%= form_for(@call) do |f| %>
<%= f.label :cancel_reason %>
<%= f.collection_select(:cancel_reason_id, CancelReason.all, :id, :reason, {}, {:class => 'select'}) %>
<%= f.button :submit %>
<% end %>
我尝试创建一个单独的 cancel_reason 操作并添加一个路由,但它显然也利用了更新操作并将 transfer_date 设置为 NULL。
我真的需要这个功能才能工作,但我现在的故障排除技能已经结束。
任何帮助将不胜感激。