button_to with GET method option in Rails

≯℡__Kan透↙ 提交于 2019-12-03 10:06:55

Buttons aren't supposed to be sending GET requests.

You should use a link_to instead. If you want it to look like a button, apply some CSS. Here's a good article: http://coding.smashingmagazine.com/2009/11/18/designing-css-buttons-techniques-and-resources/

Just use method: and :get

button_to "New User", new_user_path, method: :get

You may want to look at the UJS driver code:

a\[data-method\] is the selector used here:

So the following should work (couldn't really test it):

button_to "Tutor", {...}, :html => { "data-method" => "get" }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!