0

I can send the param x=y in a form with a hidden field like this

<%= form_with(url: '/search', method: 'get') do %>
  <%= text_field_tag(:query) %>
  <%= hidden_field_tag(:x, 'y') %>
  <%= submit_tag("Search") %>
<% end %>

Is it possible to send params in the URL? The following doesn't work

<%= form_with(url: '/search?x=y', method: 'get') do %>
  <%= text_field_tag(:query) %>
  <%= submit_tag("Search") %>
<% end %>
vince
  • 2,374
  • 4
  • 23
  • 39

1 Answers1

1

As you can read here, the query string that you might have in a HTML form action attribute will not taken into account.

Translated into your form_for problem, it means that the query string that you have in your url: are not taken into account.

Hence, your hidden_field_tag is the right solution for this problem.

Yanou
  • 929
  • 8
  • 8