【发布时间】:2017-03-13 02:21:02
【问题描述】:
我正在通过按下视图的保存按钮来运行控制器操作“保存”。 “post”操作重定向到“print_pdf”操作,然后通过 prawn 呈现 pdf。问题是保存按钮仍然处于禁用状态。您不能按下按钮,但视图中的其他控件可以工作。将保存按钮恢复到启用状态的唯一方法是单击浏览器“刷新”。我尝试了 redirect_to :back 和其他各种黑客,但最终出现错误。每个控制器操作不能执行多个重定向。任何想法如何启用保存按钮或为什么它仍然/导致禁用?请。
#view
<%= form_for(@pdf_report_run) do |f| %>
<div> class="some_class">
<%= f.submit("Save", class: 'btn btn-primary') %>
#controller
def create
format.html { redirect_to print_pdf(format: 'pdf') }
end
def print_pdf
@self = self
respond_to do |format|
format.pdf {render layout: false}
end
end
# file print_pdf.pdf
# this contains the view the controller will render
pdf = Prawn::Document.new
...
end
# the line below is the last line that gets ran (last line of the controller's view)
@self.send_data pdf, filename: 'file_name.pdf', type: 'application/pdf'
# i've tried redirect_to and render here but won't allow another
【问题讨论】:
-
如何从您的视图和控制器添加代码,或者您希望我们侵入您的本地计算机并以这种方式查看您的代码?
-
请同时粘贴“保存”按钮所在的视图代码。
标签: ruby-on-rails redirect controller prawn