Can I drop '?' in form triggered GET request?

二次信任 提交于 2020-01-03 08:37:09

问题


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...


回答1:


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.



来源:https://stackoverflow.com/questions/8122014/can-i-drop-in-form-triggered-get-request

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