我在TicketsController#update中得到一个AbstractController :: DoubleRenderError。 如果我选择特定用户,则不会进行更新。
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 :(得分:2)
由于您已经在if else语句中使用了redirect_to,并且在执行if else之后再次重定向,导致此错误(您可以在每个操作中仅使用一次)。为了解决这个问题,我建议采用以下解决方案(问题不明确,所以我可能不对):
解决方案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(我不确定您希望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"