0

In http://localhost:3000/services/1 I have a button to the current page with params:

 <%= button_to table.seats, service_path(@service, table_id: table.id), method: :get, class=["btn"] %>

On page, I see correct:

<form class="button_to" method="get" action="/services/1?table_id=3">
  <input class="btn" type="submit" value="2">
</form>

But in the service_controller I have a breakpoint and can not see the params[:table_id] = 3

(byebug) params
{"controller"=>"services", "action"=>"show", "id"=>"1"}

What am I doing wrong?

UPDATE:

If I get the current absolute url in controller and obtain:

(byebug) request.original_url
"http://localhost:3000/services/1"

but the link in the button was:

action="/services/1?table_id=3"

How is it possible?

John Fadria
  • 1,863
  • 2
  • 25
  • 31

1 Answers1

0

You can't include a query string in the action attribute of a form. You need to pass the table id in a hidden input.

submitting a GET form with query string params and hidden params disappear

linesarefuzzy
  • 1,890
  • 17
  • 17
  • You probably want to use the more standard [Rails form helpers](http://guides.rubyonrails.org/form_helpers.html) instead of `button_to`. – linesarefuzzy Feb 13 '15 at 18:58