2012-03-08 20 views
1

TicketsController#updateでAbstractController :: DoubleRenderErrorを取得します。 特定のユーザーを選択した場合、更新は行われていません。あなたはすでにあなたの場合はelse文の中に、あなたは(あなたが各アクションの中に一度だけ使用することができます)このエラーをリードされ、再びリダイレクトされている他の場合の実行後にredirect_toを使用してきたようにAbstractController :: DoubleRenderError in TicketsController#update

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 
+0

スタックトレースはどうですか? – nicholaides

+0

最後の 'redirect_to'を' TicketHistory.create_ticket_history'の行の後に移動して、 'return'sをすべて削除するのはなぜですか?それは条件付き論理をはるかに明確にするでしょう。 –

+0

FYI: 'if((@selected_group!= nil)&&(@selected_company!= nil))'は 'if @selected_group && selected_company'と書かれていなければなりません。非常にきれい。 –

答えて

2

ソリューション1:あなたの最後のredirect_toが必要とされていない場合、それを削除し、すなわち

これを解決するために、私は次の解決策を(質問が明確ではなかったので、私は右ではないかもしれない)ことをお勧め
redirect_to :controller => 'tickets' , :action => 'show', :id => params[:id],:test_id => @test,:ticket_id=> params[:ticket_id] 

ソリューション2:すべてのredirect_toでand returnとあなたの成功の応答条件であなたの最後のredirect_toを移動する、すなわち

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 
(私はあなたがあなたの Ticket#showを配置したい場所はわからない)で更新

P.S.:redirect_toとflash [:message]を1行で使用できます。

redirect_to your_path(params), :notice => "your message" 
関連する問題