我正在我的Rails项目(Rails 6,Ruby 2.6.6)上建立一个子域系统。
我使用以下代码让子域系统工作得很好
constraints subdomain: 'chef' do
devise_for :chefs, controllers: { registrations: 'chefs/registrations' },
resources :chefs do
resources :chef_profiles
end
end但是我想改变URI的表示方式。
目前,如果我想查看chef_profile -路由是chef.domain.com/chefs/:id/chef_profile/:id,我希望它是chef.domain.com/chef_name
对如何改变嵌套的工作方式有什么想法吗?尝试执行as: :...,但不知道在as部件中放入什么内容。
提前感谢您的帮助!
发布于 2020-07-22 04:52:59
不劫持其余路由的最简单方法是只使用get匹配器:
constraints subdomain: 'chef' do
get "/:chef_name", to: "chef_profiles#show", chef_name: /-?[a-z0-9][a-z0-9\-\_]*/i
end您可能需要调整chef_name正则表达式以适合您的模式。
https://stackoverflow.com/questions/63021625
复制相似问题