我需要一串 html(类似于"<html><body>Hello World</body></html>"
)用于传真目的。
我把它写到一个单独的 erb 文件中:views/orders/_fax.html.erb
,并尝试渲染 erb 在行动:html_data = render(:partial => 'fax')
。
这是引发问题的控制器的一部分:
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
它给了我一个 AbstractController::DoubleRenderError 如下:
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".
如何解决这个问题呢?