class Wco::OfficeActionTemplatesController

def update

def update
  params[:oat][:ties_attributes].permit! rescue nil
  if params[:id]
    @oat = OAT.find params[:id]
  else
    @oat = OAT.new
  end
  authorize! :upsert, @oat
  if params[:oat][:ties_attributes]
    params[:oat][:ties_attributes].each do |k, v|
      if !v[:next_office_action_template_id].present?
        params[:oat][:ties_attributes].delete( k )
      end
      if v[:to_delete] == "1"
        OATT.find( v[:id] ).delete
        params[:oat][:ties_attributes].delete( k )
      end
    end
  end
  if @oat.update params[:oat].permit!
    flash_notice @oat
  else
    flash_alert @oat
  end
  redirect_to action: :index
end