I am currently creating a web application with Rails, but there is a problem that cannot be solved in the routing part, so please let me know if you understand.
What do you want to do
When the show action of the article (articles) is called, the routing is now hoge.com/articles/( article id)
.I would like to do it /hoge.com/(username)/( article id)
, but it's hard to do it
The routes.rb contains:
device_for:users,controllers:{omaniauth_callbacks:'omaniauth_callbacks'}
revise_scope —user do
resources —articles
get'/:username', controller: 'users', action: 'show'
get '/users/sign_out', controller: 'device/sessions', action: 'destroy'
get 'users/auth/:provider/disconnect', controller: 'omniauth_disconnects', action: 'update'
end
post 'user_invitation_beta_release/new'
get 'static/welcome'
root to: 'root#index'
resources:items
resources:contents
resources —articles do
resources:contents, only:[:create,:destroy,:change_order] do
resources:items, only:[:create,:destroy]
end
end
match "*path" = > "application#handle_404", via: :all
I think the following description is acceptable, but what do you think?
get'/:username/:id'=>'articles#show'
© 2024 OneMinuteCode. All rights reserved.