Ruby on rails 如何基于Rails3.0.x中的表单选项指定响应格式

Ruby on rails 如何基于Rails3.0.x中的表单选项指定响应格式,ruby-on-rails,ruby-on-rails-3,webforms,prawn,prawnto,Ruby On Rails,Ruby On Rails 3,Webforms,Prawn,Prawnto,环境:Rails 3.0.4和Ruby 1.9.2 我有以下表格: <%= form_tag( {:action => 'show', :format => :pdf}, :method => :post) do %> .. list of items ... <%= submit_tag "Show", :onclick => "return checkAllFields(4);", :remote => true %> <s

环境:Rails 3.0.4和Ruby 1.9.2

我有以下表格:

<%= form_tag( {:action => 'show', :format => :pdf}, :method => :post) do %>

.. list of items ...

<%= submit_tag "Show", :onclick => "return checkAllFields(4);", :remote => true %> 

<select name="format">
    <option name="HTML">HTML</option>
    <option name="PDF">PDF</option>
</select>) 

<% end %>

我会尝试以下方法:

首先,您可能需要从表单标记中删除硬编码的
:format=>:pdf
(因为它可能会覆盖下面的选项)

接下来,确保
select
标记传递了正确的值。您可以使用以下帮助程序:

select_tag :format, options_for_select([["HTML", "html"], ["PDF", "pdf"]], "html")
返回类似以下HTML的内容:

<select id='format' name='format'>
  <option value='html' selected='selected'>HTML</option>
  <option value='pdf'>PDF</option>
</select>

HTML
PDF

我不是100%确定,但是没有通过
:remote=>true
选项自动使格式
js
?仔细想想,在查看代码后,我认为您不能这样设置
格式,因为
respond\u to
块中列出的
格式实际上是一个
收集器。我过一会儿再仔细看看。布兰登,你说得对。不需要:remote=>true。(不过,在这种情况下似乎没有任何效果)。:format=>:pdf具有将.pdf附加到URL的预期效果,但据我所知,这会触发respond_to block中的正确行。
<select id='format' name='format'>
  <option value='html' selected='selected'>HTML</option>
  <option value='pdf'>PDF</option>
</select>