在Rails中使用GET方法选项的button_to
我有以下按钮,我将其覆盖以生成GET请求:
= button_to "Tutor", {:controller => "appointments", :action => "new", :listing_id => @listing.id} , :method => :get
但是,我仍然得到一个带有额外参数的POST请求:方法:
Processing by AppointmentsController#new as HTML Parameters: {"authenticity_token"=>"AWkL", "listing_id"=>"2", "method"=>"get"}
我的路线档案,我有:
resources :appointments
我做错了什么?
谢谢。
按钮不应该发送GET
请求。
你应该使用link_to
。 如果您希望它看起来像一个按钮,请应用一些CSS。 这是一篇很好的文章: http : //coding.smashingmagazine.com/2009/11/18/designing-css-buttons-techniques-and-resources/
只需使用方法 :和:get
button_to "New User", new_user_path, method: :get
您可能想查看UJS驱动程序代码 :
a\[data-method\]
是这里使用的选择器:
所以以下应该工作(无法真正测试它):
button_to "Tutor", {...}, :html => { "data-method" => "get" }