Dave Dave - 1 year ago 103
Ajax Question

Why is Rails button_to designation ignoring my method speicifcation?

I’m using Rails 4.2.7. I’m trying to create a button with a GET submit method, so I created

<span class="buttonContainer"><%= button_to "Save", user_my_object_time_matches_create_path(:id => @my_object_time.id), :method => "GET", :class => 'btn saveDetails', :remote => true %></span>

but what is actually getting created is a form with a POST action.

<form class="button_to" method="post" action="/user_my_object_time_matches/create?id=d64bbe61-21cc-477a-aa11-ab4ff5cac66c" data-remote="true"><input class="btn saveDetails" type="submit" value="Save"><input type="hidden" name="authenticity_token" value="ENx/qK8hoRdR1DVa/99rQGQeJiaoQNPXx6k/xTwDy6KkPAUC1KyHM8qiC1SiCbeNsgghhMh7sjsu8c+2e7cnfg=="></form>

What am I doing wrong in the above? How do I get the above to become a GET submit?

Answer Source

The allowed values for :method are the symbols :get, :post, :put, :patch and :delete. Use method: :get, not method: 'GET'.

The string 'get' will work, as a quirk of button_to's implementation, but that shouldn't be depended upon. The string 'GET' absolutely will not work, and will instead use the default value for :method, which is :post.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download