Rails 路由不可见前缀

Rails routes invisible prefix

嗨,我在 rails 路由中的前缀是不可见的。

这是我的文件routes.rb

Rails.application.routes.draw do

  get '/gossip/:id', to: 'gossip#show'
  get '/welcome/:user_entry', to: 'welcome#personnal'
  root 'home#show'
  get '/team', to: 'team#show'
  get '/contact', to: 'contact#show'
 end

当我在航站楼 运行 rails 路由时,我看到:

Prefix Verb URI Pattern                                                                              Controller#Action
                          GET  /gossip/:id(.:format)                                                                    gossip#show
                          GET  /welcome/:user_entry(.:format)                                                           welcome#personnal
                     root GET  /                                                                                        home#show
                     team GET  /team(.:format)                                                                          team#show
                  contact GET  /contact(.:format)                                                                       contact#show
       rails_service_blob GET  /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET  /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET  /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT  /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

如果我删除 id 之前的 : 我会看到前缀,但我的路由不再是动态的。有小费吗?谢谢

您可以通过添加as: :some_route_name:

来命名路由
get '/gossip/:id', to: 'gossip#show', as: :gossip

或使用:

resources :gossip, only: [:show]