使用具有自定义控制器名称的资源 [英] Using resources with custom controller names
本文介绍了使用具有自定义控制器名称的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是嵌套资源,但是遇到的控制器名称应该更具描述性。
I'm using nested resources, however i come across controller names that should be more descriptive.
例如,我有一个控制器 ProductsController
和 ImagesController
For instance i have a controller ProductsController
and ImagesController
resources :products do
resources :images
end
这很好,但是以后我可能需要将 ImageController
用于产品图像以外的其他图像,因此应将其命名为 ProductsImagesController 。
This works fine, but later i might need to use the ImageController
for other than products images, therefore it should be named ProductsImagesController.
但是我如何在 resources()
上指定控制器名称,而又不退缩到类似的丑陋之处:
But how can i specify the controller name on resources()
without falling back to something ugly like:
match 'products/images' => 'products_images#index'
match 'products/images/new' => 'products_images#new'
推荐答案
resources :products do
resources :images, :controller => "products_images"
end
这篇关于使用具有自定义控制器名称的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文