Can I drop '?' in form triggered GET reque

2019-06-17 03:33发布

问题:

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.