18

I'm just trying to create a simple select menu that takes you to a specific URL. So far I have something like this:

# haml
= form_tag new_something_path, method: :get do
  = select_tag :type, options_for_select(my_array)
  = submit_tag 'New Something'

However, when I submit the form I get the UTF8 parameter as well as a "commit" parameter with the text of the button.

How can I remove the UTF8 and commit parameters?

4

2 回答 2

43

去掉commitparam比较简单,需要指定输入没有名字:

submit_tag 'New Something', name: nil

关于 UTF-8 参数……它有一个重要的用途。一旦你理解了 Rails UTF-8 参数的目的,并且由于某种原因你仍然需要删除它,解决方案比你想象的要容易......只是不要使用 form_tag 帮助器:

# haml
%form{action: new_something_path, method: 'get'}
  = select_tag :type, options_for_select(my_array)
  = submit_tag 'New Something', name: nil
于 2013-03-29T02:55:46.833 回答
2

utf8您可以通过添加(and also ) 的enforce_utf8: false选项来摆脱参数,如下所示:form_tagform_form

= form_tag new_something_path, method: :get, enforce_utf8: false do

(感谢@Dmitry 指出这一点)

但请确保您不需要它:Ruby on Rails 3 表单中的 _snowman 参数是干什么用的?(我不确定它是否真的与GET表格相关。)

附加参数由提交按钮生成,可以通过设置name: false您的选项来删除submit_tag(也适用submit于 的情况form_for)。

= submit_tag 'New Something', name: nil
于 2019-07-11T14:05:27.337 回答