For example, suppose you have UsersController
and you set it in config/routes.rb
as follows:
I want root 'users#index'#root to be a list of users
resources —users
Then the routing configuration should be as follows:
Prefix Verb URI Pattern Controller#Action
root GET/users#index
users GET/users(.:format) users#index
users POST / users(.:format) users#create
new_user GET/users/new(.:format)users#new
edit_user GET/users/:id/edit(.:format)users#edit
user GET/users/:id(.:format)users#show
PATCH/users/:id(.:format)users#update
PUT/users/:id(.:format)users#update
DELETE/users/:id(.:format)users#destroy
At this time, users#index
has multiple URLs (GETs) corresponding to /
and /users
.
There is no such situation. Which one should I choose?
It was disgusting, so I used except
and only
to make it a unique URL.
There were several tutorials and sample codes on the web...
Certainly, I think it's an advantage that you can still use named routes that match the default settings.
If you have published the URL, I have heard that from the SEO's point of view, the URL should be one-on-one with the content.
If the content is duplicated, you may want to refer to the following site to add the rel=canonical
attribute.
Five common errors with rel=canonical attributes
There are advantages of using URLs that follow the naming convention, so if there is no problem, you can leave them behind. When developing with multiple people, you may have different addresses and cause problems during maintenance, so you may want to explicitly destroy them.
© 2024 OneMinuteCode. All rights reserved.