When I was looking at Rails routing, there was a description that I didn't understand, so I would like to ask you a question.
Am I correct in understanding that I will go to see the sample#show when I transition to /sample(ya/sample/hoge)?
resource:sample,controller::sample,only:[:show] do
get '*other', to: 'sample#show'
end
By the way, this sample#show is going to read SPA files
def show
render file:Rails.public_path.join('dist', 'web', 'sample', 'index.html', layout:false
end
It is written as follows:
/sample
/sample/confirm
/sample/complete
There are screen files equivalent to .
The get'*other', to:'sample#show'
portion uses a routing glove, which is routed to sample#show
when you try to get sample/somehow
.The params[:other]
part now goes into params[:other]
.
https://railsguides.jp/routing.html#Routing Globes and Wildcard Segments
A routing globe (route globbing) is a wildcard deployment that is used to match a particular parameter from a routing position to all parts below.Example:
get 'photos/*other', to: 'photos#unknown'
© 2024 OneMinuteCode. All rights reserved.