【问题标题】:Rails View Save Button DisabledRails 视图保存按钮已禁用
【发布时间】: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


【解决方案1】:

这是 Rails 5 的一个功能,要解决这个问题,这里有一个快速破解方法

不要使用&lt;%= f.submit("Save", class: 'btn btn-primary') %&gt;,而是使用这个

<%= button_tag 'Save', class: 'btn btn-primary' %>

希望有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-12
    • 2017-04-11
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    • 1970-01-01
    相关资源
    最近更新 更多