Is the "resources" function in routes.rb only responsible for creating the URLs needed to access a resource?

StackOverflow https://stackoverflow.com/questions/23614992

  •  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?

도움이 되었습니까?

해결책

/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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top