【发布时间】:2016-07-04 22:37:27
【问题描述】:
我正在编写 rails 应用程序,我需要更改我的应用程序的一些 URL 路径。但我不想破坏我的测试并在视图、js 或控制器中进行更改...
这是我的路线:
resources :posts, path: 'news' do
member do
get 'edit/page/:page', as: :edit, action: :edit
post '/approve', as: :approve, action: :approve
post '/reject', as: :reject, action: :reject
end
collection do
get :my
get :shared_with_me
get :filtered
end
end
如您所见,我找到了一种将所有网站路径中的 domain.com/posts 更改为 domain.com/news 的方法。
现在我需要更改此路径列表:
- 从
domain.com/news到domain.com/news/all(得到posts#index) - 从
domain.com/news/12到domain.com/news/preview/12(得到posts#show) - 从
domain.com/news/new到domain.com/news/request(得到posts#new)
我正在尝试使用 :path_names 更改此路径,但它不起作用...
这里是更新的路线:
resources :posts, path: 'news', path_names: {index: 'all', show: 'preview', new: 'request'} do
member do
get 'edit/page/:page', as: :edit, action: :edit
post '/approve', as: :approve, action: :approve
post '/reject', as: :reject, action: :reject
end
collection do
get :my
get :shared_with_me
get :filtered
end
end
当我进行此更改并运行 rake routes - 仅出现 GET news/request..
但为什么我没有看到 GET news/all 和 GET news/:id/review ?
请帮我解决它。 谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 routes rails-routing