我有一个书籍模型,其中定义了各种路线:
resources :books do
member do
get 'printable_version'
end
collection do
get 'search'
get 'recently_added'
end
resources :pages do
collection do
get 'new'
get 'edit_all'
post 'update_all'
end
end
# I put a namespace declaration here
# namespace :marketing do
# get 'mini_flyer'
# end
end
我现在想要的是一个“营销”“子目录”,这意味着我希望能够访问这样的路线:
/books/24/marketing/mini_flyer
或者/book/10/marketing/large_flyer
我试图将命名空间放入资源块中,但这是我从中得到的rake routes
:
book_marketing_mini_flyer GET /books/:book_id/marketing/mini_flyer(.:format) marketing/books#mini_flyer
/app/controllers/marketing/books_controller.rb
当我真正想要它去的时候,这条路线匹配到/app/controllers/books/marketing_controller.rb
。那可能吗?
- 编辑 -
我也可以走这条路(双关语):
resources :books do
resource :marketing, to: "books/marketing" do
collection do
get 'mini_flyer'
end
end
end
虽然,我不确定这是否是最好的。