Wie rendert man eine Erb-Vorlage, um sie in einer Aktion zu platzieren?

Ich brauche eine Zeichenfolge von HTML (so etwas wie"<html><body>Hello World</body></html>") zum Faxen.

Ich habe es in eine separate Erb-Datei geschrieben:views/orders/_fax.html.erb und versuche den erb in aktion zu rendern:html_data = render(:partial => 'fax').

Hier ist ein Teil des Controllers, der das Problem aufwirft:

  respond_to do |format|
      if @order.save   
        html_data = render(:partial => 'fax')
        response = fax_machine.send_fax(html_data)
        ......

        format.html { redirect_to @order, notice: 'Order was successfully created.' }
        format.json { render json: @order, status: :created, location: @order }
      else  
        format.html { render action: "new" }
        format.json { render json: @order.errors, status: :unprocessable_entity }
      end
    end

Es gab mir einen AbstractController :: DoubleRenderError wie folgt:

AbstractController::DoubleRenderError in OrdersController#create

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".

Wie kann man dieses Problem lösen?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage