当我切换到使用form_with而不是form_标签时,Wicked_PDF不会下载

当我切换到使用form_with而不是form_标签时,Wicked_PDF不会下载,pdf,ruby-on-rails-5,wkhtmltopdf,wicked-pdf,Pdf,Ruby On Rails 5,Wkhtmltopdf,Wicked Pdf,我注意到我的观点中有一个bug,在初次提交生成PDF后,我的表单无法提交,在研究过程中,我发现form_with是使用rails构建表单的推荐方法。我更新了我的表单,一切似乎都按照预期的方式运行,但现在PDF不像以前那样下载,只是在响应中呈现字符串而不生成文件。使用Wicked PDF和Rails 5.2.1。对不起,我错过了一些非常明显的东西 按预期使用form_tag pdf下载: 视图中的表格: <%= form_tag("download_pdf", format: :pdf, m

我注意到我的观点中有一个bug,在初次提交生成PDF后,我的表单无法提交,在研究过程中,我发现form_with是使用rails构建表单的推荐方法。我更新了我的表单,一切似乎都按照预期的方式运行,但现在PDF不像以前那样下载,只是在响应中呈现字符串而不生成文件。使用Wicked PDF和Rails 5.2.1。对不起,我错过了一些非常明显的东西

按预期使用form_tag pdf下载:

视图中的表格:

<%= form_tag("download_pdf", format: :pdf, method: "get") do %>
    <div class="input-group mb-3">
      <%= collection_select(:location, :id, Location.all, :id, :name, {:include_blank => 'Filter by location'}, {:id => 'qr_code_loc_select', :selected_value => '', :name => 'location', :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= collection_select(:name, :id, DeviceType.all, :id, :name, {:include_blank => 'Filter by device type'}, {:id => 'qr_device_type_select', :selected_value => '', :name => "device_type", :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <input type="number" name="width" class="form-control label_size_input" id="label_width" step="0.001" placeholder="Label Width" autocomplete ='off' aria-describedby="basic-addon3">
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <div class="input-group mb-3">
      <input type="number" name="height" class="form-control label_size_input" id="label_height" step="0.001" placeholder="Label Height" autocomplete ='off' aria-describedby="basic-addon3">
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <%= label_tag "qr_col", "Columns:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= select_tag "qr_col", options_for_select(["1","2", "3", "4", "5"], "3"), {:autocomplete => 'off'}%>
    </div>
    <%= label_tag "paper_size", "Paper Size:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= select_tag "paper_size", options_for_select(@paper_size, "A4"), {:autocomplete => 'off'}%>
    </div>
    <div class="btn-group mb-3" role="group" aria-label="pdf_export_button" id="pdf_export">
      <%= hidden_field_tag :column_number %>
      <%= hidden_field_tag :label_size %>
      <%= hidden_field_tag :format, "pdf" %>
      <%= submit_tag("Create PDF Document", {:class=> "btn btn-secondary"}) %>
      <% end %>
    </div>
 <%= form_with url: download_pdf_path(format: :pdf), method: "get" do |f| %>
    <div class="input-group mb-3">
      <%= f.collection_select(:id, Location.all, :id, :name, {:include_blank => 'Filter by location'}, {:id => 'qr_code_loc_select', :selected_value => '', :name => 'location', :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= f.collection_select(:id, DeviceType.all, :id, :name, {:include_blank => 'Filter by device type'}, {:id => 'qr_device_type_select', :selected_value => '', :name => "device_type", :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= f.number_field nil, {:name => "width", :id => "label_width", :class => "form-control label_size_input", :step => "0.001", :placeholder => "Label Width", :autocomplete => 'off'} %>
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <div class="input-group mb-3">
      <%= f.number_field nil, {:name => "height", :id => "label_height", :class => "form-control label_size_input", :step => "0.001", :placeholder => "Label Height", :autocomplete => 'off'} %>
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <%= label_tag "qr_col", "Columns:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= f.select "column_number", options_for_select(["1","2", "3", "4", "5"], "3"), {:autocomplete => 'off'}, :id => "qr_col"%>
    </div>
    <%= label_tag "paper_size", "Paper Size:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= f.select "paper_size", options_for_select(@paper_size, "A4"), {:autocomplete => 'off'}%>
    </div>
    <div class="btn-group mb-3" role="group" aria-label="pdf_export_button" id="pdf_export">
      <%= f.hidden_field :label_size %>
      <%= f.submit("Create PDF Document", {:class=> "btn btn-secondary", :data => { turbolinks: false }}) %>
    </div>
  <% end %>
在控制台中:

    Started GET "/qr_codes/download_pdf?utf8=%E2%9C%93&location=&device_type=&width=&height=&qr_col=3&paper_size=A4&column_number=3&label_size=&format=pdf&commit=Create+PDF+Document" for 127.0.0.1 at 2018-11-14 20:03:51 -0500
    Processing by QrCodesController#download_pdf as PDF
      Parameters: {"utf8"=>"✓", "location"=>"", "device_type"=>"", "width"=>"", "height"=>"", "qr_col"=>"3", "paper_size"=>"A4", "column_number"=>"3", "label_size"=>"", "commit"=>"Create PDF Document"}
      Rendering qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb
       (0.4ms)  SELECT COUNT(*) FROM "devices"
      Device Load (0.6ms)  SELECT "devices".* FROM "devices"
      Rendered qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb (778.0ms)
    "***************[\"/Users/joe/.rbenv/versions/2.5.0/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf20181114-912-1opkhpt.html\", \"/var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf_generated_file20181114-912-m57i12.pdf\"]***************"
      Rendering text template
      Rendered text template (0.1ms)
    Sent data report.pdf (1.7ms)
    Completed 200 OK in 3077ms (Views: 1.2ms | ActiveRecord: 1.0ms)
    Started GET "/qr_codes/download_pdf_path?utf8=%E2%9C%93&location=&device_type=&width=&height=&column_number=3&paper_size=A4&label_size=&format=pdf&commit=Create%20PDF%20Document" for 127.0.0.1 at 2018-11-14 20:01:04 -0500
    Processing by QrCodesController#download_pdf as PDF
      Parameters: {"utf8"=>"✓", "location"=>"", "device_type"=>"", "width"=>"", "height"=>"", "column_number"=>"3", "paper_size"=>"A4", "label_size"=>"", "commit"=>"Create PDF Document"}
      Rendering qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb
       (0.3ms)  SELECT COUNT(*) FROM "devices"
      Device Load (1.2ms)  SELECT "devices".* FROM "devices"
      Rendered qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb (453.5ms)
    "***************[\"/Users/joe/.rbenv/versions/2.5.0/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf20181114-912-1ym4a9q.html\", \"/var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf_generated_file20181114-912-edkha0.pdf\"]***************"
      Rendering text template
      Rendered text template (0.1ms)
    Sent data PDF Report-14-NOV-2018 20:01:07 (1.6ms)
    Completed 200 OK in 2682ms (Views: 1.1ms | ActiveRecord: 1.5ms)
将表单_与pdf一起使用不会按预期生成,并且只有一个未格式化的字符串作为响应:

视图中的表格:

<%= form_tag("download_pdf", format: :pdf, method: "get") do %>
    <div class="input-group mb-3">
      <%= collection_select(:location, :id, Location.all, :id, :name, {:include_blank => 'Filter by location'}, {:id => 'qr_code_loc_select', :selected_value => '', :name => 'location', :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= collection_select(:name, :id, DeviceType.all, :id, :name, {:include_blank => 'Filter by device type'}, {:id => 'qr_device_type_select', :selected_value => '', :name => "device_type", :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <input type="number" name="width" class="form-control label_size_input" id="label_width" step="0.001" placeholder="Label Width" autocomplete ='off' aria-describedby="basic-addon3">
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <div class="input-group mb-3">
      <input type="number" name="height" class="form-control label_size_input" id="label_height" step="0.001" placeholder="Label Height" autocomplete ='off' aria-describedby="basic-addon3">
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <%= label_tag "qr_col", "Columns:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= select_tag "qr_col", options_for_select(["1","2", "3", "4", "5"], "3"), {:autocomplete => 'off'}%>
    </div>
    <%= label_tag "paper_size", "Paper Size:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= select_tag "paper_size", options_for_select(@paper_size, "A4"), {:autocomplete => 'off'}%>
    </div>
    <div class="btn-group mb-3" role="group" aria-label="pdf_export_button" id="pdf_export">
      <%= hidden_field_tag :column_number %>
      <%= hidden_field_tag :label_size %>
      <%= hidden_field_tag :format, "pdf" %>
      <%= submit_tag("Create PDF Document", {:class=> "btn btn-secondary"}) %>
      <% end %>
    </div>
 <%= form_with url: download_pdf_path(format: :pdf), method: "get" do |f| %>
    <div class="input-group mb-3">
      <%= f.collection_select(:id, Location.all, :id, :name, {:include_blank => 'Filter by location'}, {:id => 'qr_code_loc_select', :selected_value => '', :name => 'location', :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= f.collection_select(:id, DeviceType.all, :id, :name, {:include_blank => 'Filter by device type'}, {:id => 'qr_device_type_select', :selected_value => '', :name => "device_type", :style=> 'width: 17em', :autocomplete => 'off'}) %>
    </div>
    <div class="input-group mb-3">
      <%= f.number_field nil, {:name => "width", :id => "label_width", :class => "form-control label_size_input", :step => "0.001", :placeholder => "Label Width", :autocomplete => 'off'} %>
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <div class="input-group mb-3">
      <%= f.number_field nil, {:name => "height", :id => "label_height", :class => "form-control label_size_input", :step => "0.001", :placeholder => "Label Height", :autocomplete => 'off'} %>
      <div class="input-group-append">
        <span class="input-group-text">inches</span>
      </div>
    </div>
    <%= label_tag "qr_col", "Columns:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= f.select "column_number", options_for_select(["1","2", "3", "4", "5"], "3"), {:autocomplete => 'off'}, :id => "qr_col"%>
    </div>
    <%= label_tag "paper_size", "Paper Size:", class:"ml-2 text-light" %>
    <div class="input-group mb-3">
        <%= f.select "paper_size", options_for_select(@paper_size, "A4"), {:autocomplete => 'off'}%>
    </div>
    <div class="btn-group mb-3" role="group" aria-label="pdf_export_button" id="pdf_export">
      <%= f.hidden_field :label_size %>
      <%= f.submit("Create PDF Document", {:class=> "btn btn-secondary", :data => { turbolinks: false }}) %>
    </div>
  <% end %>
在控制台中:

    Started GET "/qr_codes/download_pdf?utf8=%E2%9C%93&location=&device_type=&width=&height=&qr_col=3&paper_size=A4&column_number=3&label_size=&format=pdf&commit=Create+PDF+Document" for 127.0.0.1 at 2018-11-14 20:03:51 -0500
    Processing by QrCodesController#download_pdf as PDF
      Parameters: {"utf8"=>"✓", "location"=>"", "device_type"=>"", "width"=>"", "height"=>"", "qr_col"=>"3", "paper_size"=>"A4", "column_number"=>"3", "label_size"=>"", "commit"=>"Create PDF Document"}
      Rendering qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb
       (0.4ms)  SELECT COUNT(*) FROM "devices"
      Device Load (0.6ms)  SELECT "devices".* FROM "devices"
      Rendered qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb (778.0ms)
    "***************[\"/Users/joe/.rbenv/versions/2.5.0/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf20181114-912-1opkhpt.html\", \"/var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf_generated_file20181114-912-m57i12.pdf\"]***************"
      Rendering text template
      Rendered text template (0.1ms)
    Sent data report.pdf (1.7ms)
    Completed 200 OK in 3077ms (Views: 1.2ms | ActiveRecord: 1.0ms)
    Started GET "/qr_codes/download_pdf_path?utf8=%E2%9C%93&location=&device_type=&width=&height=&column_number=3&paper_size=A4&label_size=&format=pdf&commit=Create%20PDF%20Document" for 127.0.0.1 at 2018-11-14 20:01:04 -0500
    Processing by QrCodesController#download_pdf as PDF
      Parameters: {"utf8"=>"✓", "location"=>"", "device_type"=>"", "width"=>"", "height"=>"", "column_number"=>"3", "paper_size"=>"A4", "label_size"=>"", "commit"=>"Create PDF Document"}
      Rendering qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb
       (0.3ms)  SELECT COUNT(*) FROM "devices"
      Device Load (1.2ms)  SELECT "devices".* FROM "devices"
      Rendered qr_codes/show.html.erb within layouts/pdf_layout.pdf.erb (453.5ms)
    "***************[\"/Users/joe/.rbenv/versions/2.5.0/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf20181114-912-1ym4a9q.html\", \"/var/folders/pf/kl12j8g91w5bj7ssc_0fdv3c0000gn/T/wicked_pdf_generated_file20181114-912-edkha0.pdf\"]***************"
      Rendering text template
      Rendered text template (0.1ms)
    Sent data PDF Report-14-NOV-2018 20:01:07 (1.6ms)
    Completed 200 OK in 2682ms (Views: 1.1ms | ActiveRecord: 1.5ms)

这是一件愚蠢的事情,我决定将注意力转向带有文档的表单_,并发现remote:true是默认设置的。如果将其设置为local:true,则问题已得到解决。希望这能帮助别人