Rails表单使用GET请求:如何删除按钮和utf8参数?

时间:2022-10-12 20:44:07

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

我只是想创建一个简单的选择菜单,将您带到特定的URL。到目前为止,我有这样的事情:

# 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.

但是,当我提交表单时,我会获得UTF8参数以及带有按钮文本的“commit”参数。

How can I remove the UTF8 and commit parameters?

如何删除UTF8并提交参数?

1 个解决方案

#1


37  

Removing the commit param is relatively simple, you need to specify that the input does not have a name:

删除提交参数相对简单,您需要指定输入没有名称:

submit_tag 'New Something', name: nil

Regarding the UTF-8 param...it serves an important purpose. Once you understand the purpose of the Rails UTF-8 param, and for some reason you still need to remove it, the solution is easier than you think...just don't use the form_tag helper:

关于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

#1


37  

Removing the commit param is relatively simple, you need to specify that the input does not have a name:

删除提交参数相对简单,您需要指定输入没有名称:

submit_tag 'New Something', name: nil

Regarding the UTF-8 param...it serves an important purpose. Once you understand the purpose of the Rails UTF-8 param, and for some reason you still need to remove it, the solution is easier than you think...just don't use the form_tag helper:

关于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