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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With