AbstractController :: DoubleRenderError в обновлении TicketsController # - PullRequest
1 голос
/ 08 марта 2012

я получаю AbstractController :: DoubleRenderError в обновлении TicketsController #. Если я выбираю конкретного пользователя, обновление не происходит.

def update

    @selected_group = Group.find_by_id(params[:Department]) unless params[:Department].nil?
    @selected_company = Company.find_by_id(params[:Company]) unless params[:Company].nil?
    @ticketnote_content = params[:Ticketnote] 

    if ((@selected_group != nil) && (@selected_company != nil))

      map_group_to_department
      map_user_to_staff
      update_ticket

      if (@response['response'] == "Failed")
        flash[:error] = response['err_desc']
        redirect_to "/ticket/#{params[:id]}/edit"
        return
      elsif (@response['response'] == "Success")
          @ticketnote_content
          if @ticketnote_content != ""
              add_note_to_ticket
         end
        map_assets_findings_tickets
        flash[:notice] = "Succesfully updated the ticket"
        TicketHistory.create_ticket_history(@assigned_user,@selected_asset,@ticket_params,current_user,@updated_ticket_response,"Updated")
      end
    else

      flash[:error] = "Company or department can't be blank."
      redirect_to "/ticket/#{params[:id]}/edit"
      return
    end
    redirect_to :controller => 'tickets' , :action => 'show', :id => params[:id],:test_id => @test,:ticket_id=> params[:ticket_id]
end

1 Ответ

2 голосов
/ 09 марта 2012

Поскольку вы уже использовали redirect_to в своем операторе if else и после выполнения if else вы перенаправляете снова, что приводит к этой ошибке (вы можете использовать только один раз в каждом действии). Чтобы решить эту проблему, я бы предложил следующие решения (вопрос был неясен, поэтому я могу быть не прав):

Решение 1 : Если ваш последний redirect_to не требуется, удалите его, т.е.

redirect_to :controller => 'tickets' , :action => 'show', :id => params[:id],:test_id => @test,:ticket_id=> params[:ticket_id]

Решение 2 : обновить с and return в каждом redirect_to и переместить вас последним redirect_to в ваше условие успешного ответа (я не уверен, где вы хотите Ticket#show), то есть

def update
  @selected_group = Group.find_by_id(params[:Department]) unless params[:Department].nil?
  @selected_company = Company.find_by_id(params[:Company]) unless params[:Company].nil?
  @ticketnote_content = params[:Ticketnote] 

  if @selected_group && @selected_company
    map_group_to_department
    map_user_to_staff
    update_ticket

    if (@response['response'] == "Failed")
      flash[:error] = response['err_desc']
      redirect_to "/ticket/#{params[:id]}/edit"
    elsif (@response['response'] == "Success")
      add_note_to_ticket if @ticketnote_content != ""
      map_assets_findings_tickets
      flash[:notice] = "Succesfully updated the ticket"
      TicketHistory.create_ticket_history(@assigned_user,@selected_asset,@ticket_params,current_user,@updated_ticket_response,"Updated")
      redirect_to :controller => 'tickets' , :action => 'show', :id => params[:id],:test_id => @test,:ticket_id=> params[:ticket_id]
    end
  else
    flash[:error] = "Company or department can't be blank."
    redirect_to "/ticket/#{params[:id]}/edit" and return
  end 
end

P.S. : Вы можете использовать redirect_to и flash [: message] в одну строку:

redirect_to your_path(params), :notice => "your message"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...