我有一個應用程序,其中包含調用。我希望能夠取消通話並提供通話取消的原因。到目前爲止,我有我的取消行動在控制器中工作,但我試圖找出如何擴大它,所以在它發佈「取消」到call_status
字段之前,它也將基於下拉列表填充cancel_reason
字段。Rails取消確認信息原因
這是我到目前爲止有:
視圖代碼:取消按鈕
<%= link_to 'Cancel',
cancel_call_path(call),
confirm: 'Are you sure you want to cancel the call?',
:method => :post,
:class => 'btn btn-danger btn-mini' %>
控制器代碼:取消動作
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
redirect_to calls_url, :notice => "Call was successfully cancelled"
else
redirect_to calls_url, :error => "Whoops."
end
end
我想任一確認彈出所示,用取消的原因,或取消動作綁在不同視圖中,帶有小的形狀,即包括一原因。
問題是什麼? –