Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails form using GET request: How to remove button and utf8 params?

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?

like image 840
Andrew Avatar asked Mar 28 '13 19:03

Andrew


2 Answers

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:

# haml
%form{action: new_something_path, method: 'get'}
  = select_tag :type, options_for_select(my_array)
  = submit_tag 'New Something', name: nil
like image 121
Andrew Avatar answered Nov 17 '22 00:11

Andrew


You can get rid of the utf8 param by adding the enforce_utf8: false option of form_tag (and also form_form) like the following:

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

(thanks to @Dmitry for pointing that out)

But please make sure you don't need it: What is the _snowman param in Ruby on Rails 3 forms for? (I'm not sure if it is actually relevant for GET forms.)

The additional parameter is generated by the submit button can be removed by setting the name: false option on your submit_tag (Also works for submit in case of form_for).

= submit_tag 'New Something', name: nil
like image 36
aef Avatar answered Nov 16 '22 22:11

aef