0

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?

4

1 回答 1

1

Path 是路径,它不包含VERB(HTTP METHOD)信息。例如,默认情况下,路径showdestroy资源操作是相同的,并且您使用相同的路径助手(但不同的 HTTP 方法):

<%= 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 %>

重定向总是使用get.

于 2014-12-12T14:57:23.207 回答