2015-04-12 3 views
1

Après la mise à niveau mes Rails 4 application pour Rails 4.2 Je reçois cette erreur:DoubleRenderError après la mise à niveau Rails 4.2

AbstractController::DoubleRenderError in InvoicesController#download

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

Ceci est le contrôleur en question:

class InvoicesController < ApplicationController 

    def download 
    @invoice = Invoice.find_by(:download_code => params[:id]) 
    if @invoice 
     respond_to do |format| 
     format.pdf { |pdf| render_pdf("attachment") } 
     end 
    else 
     flash[:notice] = "File cannot be found." 
     redirect_to signin_path 
    end 
    end 

    private 

    def render_pdf(disposition = "inline") 
    pdf = InvoicePdf.new(@invoice, view_context)  
    options = { :filename => invoice_filename(@invoice), :type => "application/pdf", :disposition => disposition } 
    send_data(pdf.render, options) 
    end 

end 

Toute idée de ce que je suis manquant ici?

Merci pour toute aide.

+0

Avez-vous un 'before_action' caché dans' ApplicationController'? Une autre idée peut-être stupide: essayez de renommer 'render_pdf' en' create_pdf'. – janfoeh

+0

Avez-vous essayé en supprimant le bloc 'respond_to' et en ne conservant que ce' render_pdf ("attachment")} '? –

+0

@janfoeh: Merci mais non, il n'y a pas de "before_action" dans ce cas. Et renommer n'a pas fait l'affaire non plus. – Tintin81

Répondre

1

Il s'avère que j'ai simplement dû ajouter and return à la fin de la ligne pour que cela fonctionne. Je ne suis pas sûr à 100% pourquoi cela est nécessaire, cependant. Peut-être que quelqu'un peut faire la lumière sur cela.

respond_to do |format| 
    format.pdf { |pdf| render_pdf("attachment") and return } 
end