I am using Ruby on Rails to create my application and using THIN server on heroku.
Currently using Rails 3.2.8
I ran into this bizzar behavior that I don’t understand.
A link was created using the link_to helper within the nav bar. I want to explicitly use the HTTP GET method so my ruby code was written like so:
<%=link_to "FAQ",help_path,:method=> :get %>
The resulting html looks like so:
<a data-method="get" href="/en/help">FAQ</a>
If I run rake routes, help_path appears like this:
help (/:locale)/help(.:format) static_pages#Help {:locale=>/en}
However, when I take a look at what is going on with the URL in Firebug (using the Net tab), it looks like POST was used instead of the GET method.
So instead of seeing:
GET help
this was seen instead:
POST help
If I remove the explicit call for get method like so:
<%=link_to "FAQ",help_path %>
which results in this:
<a href="/en/help">FAQ</a>
Then, in firebug -> Net, I won’t even see this URL: GET help
Under the URL column, it will show this instead:
? undefined
Wehn the URL is undefined, the Rails app on heroku will attempt to load every asset file individually, instead of loading precompiled manifest asset file.
Has anyone experience this situation? I cannnot quite figure out where in the magical black box of Rails or heroku or the thin server could be changing the behavior of the get and post method.
Any suggestions is greatly appreciated!
I will start saying that I don’t see a reason why to make a link_to and explicitly state :get as the :method. It is the default behavior anyway.
To your question: You see a POST request because when you use the :method option of link_to it generates a form which posts to the desired URL and a _method hidden input with the desired request type (POST/PUT/DELETE/GET). Rails knows how to deal with POST requests which include the _method param and responds with the proper route. In your case – the route which matches the GET action.
You can read more on link_to here.
EDIT:
I read the documentation more thoroughly and it looks like the :method option does not support :get as a value.