moosefetcher
moosefetcher

Reputation: 1901

Rails: What in my code determines which http verb is used in a route 'call'?

On the Rails Routing from the outside in page, in section 2.2, there's talk of how the http verbs and URLs are used to match 4 URLs to 7 paths.

In section 2.3 it explains how helper paths are available and, sure enough, there are the 4 paths that appear to correspond with those in the table in section 2.2.

I'd like to know what determines which VERB is used when a path is called. For instance, say I have resource :photos and I call:

redirect_to photo_path(10)

WHAT tells me which of the 3 available verbs for that option (GET, PUT/PATCH or DELETE - according to the table in section 2.2 above) will be included as part of the route?

Upvotes: 1

Views: 554

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

Path is path, it doesn't include VERB (HTTP METHOD) information. For example, path to show and destroy resource actions are by default the same and you use the same path helper (but different HTTP method):

<%= link_to 'show photo', photo_path(photo) %> <!-- returns 'default' link, so GET method is used here -->
<%= link_to 'delete photo', photo_path(photo), method: :delete %>

Redirects are performed always with get.

Upvotes: 1

Related Questions