/signup
isn’t replacing /users/new
, it’s complementing it. It’s common to create shortcuts for certain paths, especially for URLs that are more comprehensible to users.
Is the "resources" function in routes.rb only responsible for creating the URLs needed to access a resource?
-
20-07-2023 - |
문제
Rails.application.routes.draw do
resources :users
match '/signup', to: 'users#new', via:'get'
end
In this tutorial, we have a user
model. The author had us use resources :users
to have rails generate the REST style URLs (/users, /users/new, etc). But then in the second line, he has us match /signup
to users#new
. If this line wasn't here, we would only be able to access users#new using the REST url generated with the resources :users
line. In this case, it would be /users/new
. But now, he has it setup so that if we want to access users#new, we just need to access /signup
.
By matching /signup
to users#new
, are we technically completely neglecting the route that the resources
function created for us? As far as I know, for users#new, the only thing resources
did was route /users/new
to users#new
, but he isn't using that anymore. Is there something else that resources
does, or is he completely throwing out the URL that it generated, and replacing it with /signup
?
해결책
다른 팁
It won't get rid of the new route, it will simply map /signup
to the #new
action in addition to the normal new route.