【发布时间】:2013-11-22 11:22:08
【问题描述】:
我的 router.rb 中有这个:
namespace :me do
namespace :bills do
get :consumption_invoice, :format => :pdf
end
end
还有
resources :groups do
member do
namespace :bills do
get :consumption_invoice, :format => :pdf
end
end
end
第一个给我:
me_bills_consumption_invoice GET /me/bills/consumption_invoice(.:format) me/bills#consumption_invoice {:format=>:pdf}
consumption_invoice_bills_group GET /groups/:id/bills/consumption_invoice(.:format) bills/groups#consumption_invoice {:format=>:pdf}
在组中,调用的控制器是bills/groups#consumption_invoice,而不是我期望的groups/bills#consumption_invoice。
为什么?
谢谢
编辑
经过一番反思,这是我想要实现的目标:
/me/bills/consumption_invoice => :controller => :bills, :action => :consumption_invoice
# and
/groups/:id/bills/consumption_invoice => :controller => :bills, :action => :consumption_invoice
理想情况下,我希望在 :me 命名空间和 :groups 资源块中同时包含这些规则,以使其更易于阅读。
而且我希望能够轻松添加更多操作:
/me/bills/subscription_invoice => :controller => :bills, :action => :subscription_invoice
这就是为什么我想在其中创建一个区块:bills。
我一直在尝试很多可能性,我不能实现吗?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routing