简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM