我可以放弃吗?在表单中触发GET请求? [英] Can I drop '?' in form triggered GET request?
问题描述
我想用样式目的的按钮替换一个简单的链接。使用button_to代替link_to似乎是阻力最小的路径,而且我至少有意保持RESTful,这意味着在这种情况下有GET请求。
当余取代:
的link_to my_page,my_page_path
使用:
button_to my_page,my_path_path,:方法=> :获得
...在URL的末尾添加了一个'?'。当然,这只是一个小问题。但有没有简单的方法来删除'?',因为我没有查询字符串参数?
这是浏览器问题,而不是rails问题?当然,我可以将链接的样式设置为按钮样式,但我宁可不要... ...
GET请求数据是在URL中发送数据的请求。浏览器(任何浏览器)认识到URL中有数据的方式就是一个问号。
所以基本上,它跟Ruby根本没有任何关系。
您可以删除问号的唯一方法是使用规范网址或干净网址,该网址通常会保留数据以斜线划分。
http://www.domain.com/data/more-data/
这将需要使用apache服务器上的 .htaccess
文件完成URL重写。我认为在IIS(Windows)上它们使用了 web.config
。他们基本上使用问号将网址更改回URL,但用户看不到。
这是一种很难理解的技术,如果你想浪费时间只希望从您的网址中删除问号。
或者,您可以联系您的虚拟主机。他们可能愿意帮助你。
I want to replace a simple link with a button for styling purposes. Using button_to in place of link_to seems the path of least resistance, and I'm at least aspiring to keep things RESTful, which means a GET request in this case.
When I replace:
link_to "my_page", my_page_path
with:
button_to "my_page", my_path_path, :method => :get
... there's a '?' appended to the end of the URL. It's a small matter, of course. But is there a simple way to drop the '?', since I have no query string parameters?
Is this a browser issue, rather than a rails issue? Of course I could style the link to look like a button, but I'd rather not...
GET requests with data are requests where data is sent in the URL. The way a browser (any browser) recognises that there is data in the URL is by a question mark.
So basically, it has nothing to do with Ruby at all.
The only way you can remove the question mark is using a "canonical URL" or "clean URL" which usually holds data devided by slashes.
http://www.domain.com/data/more-data/
This will require URL rewriting which is done using a .htaccess
file on an apache server. I think on IIS (Windows) they use a web.config
for that. They basically change the URL back to an URL using a question mark, but invisible to the user.
This is a hard to understand technique and rather a waste of time if you only want to remove the question mark from your URL.
Alternatively you can contact your webhost. They may be willing to help you.
这篇关于我可以放弃吗?在表单中触发GET请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!