Rails中带有GET方法选项的button_to [英] button_to with GET method option in Rails

查看:54
本文介绍了Rails中带有GET方法选项的button_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下按钮,我将其覆盖以生成GET请求:

I have the following button, which I overwrited to generate a GET request:

= button_to "Tutor", {:controller => "appointments", :action => "new",
    :listing_id => @listing.id} , :method => :get

但是,我仍然收到带有额外参数的POST请求:方法:

However, I still get a POST request with extra params :method:

  Processing by AppointmentsController#new as HTML
  Parameters: {"authenticity_token"=>"AWkL", "listing_id"=>"2", "method"=>"get"}

我的路线文件中,我有:

I my routes file, I have:

 resources :appointments

我做错了什么?

谢谢。

推荐答案

按钮不应该是发送 GET 请求。

Buttons aren't supposed to be sending GET requests.

您应该改用 link_to 。如果您希望它看起来像一个按钮,请应用一些CSS。这是一篇好文章: http:// coding .smashingmagazine.com / 2009/11/18 / designing-css-buttons-techniques-and-resources /

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/

这篇关于Rails中带有GET方法选项的button_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆