具体功能多路线与单路线

时间:2014-10-21 21:40:46

标签: ruby-on-rails ruby-on-rails-4

我有一个rails应用程序,允许管理员处理电子退款。我遇到了一个复杂性呈指数增长的问题,因为我给了用户更多的地方来启动退款。我的路线变得疯狂,我知道必须有更好的方法。

我们假设用户可以在整个应用中的4个不同位置处理退款。这给了我12个示例路线:

get  'organization/:organization_id/invoices/refunds, to: 'refunds#index'
get  'organization/:organization_id/invoices/refunds/new, to: 'refunds#new'
post 'organization/:organization_id/invoices/refunds, to: 'refunds#create'

get  'agency/:agency_id/invoices/refunds, to: 'refunds#index'
get  'agency/:agency_id/invoices/refunds/new, to: 'refunds#new'
post 'agency/:agency_id/invoices/refunds, to: 'refunds#create'

get  'destination/:destination_id/refunds, to: 'refunds#index'
get  'destination/:destination_id/refunds/new, to: 'refunds#new'
post 'destination/:destination_id/refunds, to: 'refunds#create'

get  'dashboard/refunds, to: 'refunds#index'
get  'dashboard/refunds/new, to: 'refunds#new'
post 'dashboard/refunds, to: 'refunds#create'

这些都是同一个控制器,这意味着在我的视图中,我需要一些非常抽象的多态路径来退款,然后重定向到功能。

而不是所有这些混乱,如果我添加更多的地方退款,只会变得更加混乱,有没有更好的解决方案?拥有单一的服务路线是否有任何缺点?#34;处理所有这样的请求:

get  'refunds/new, to: 'refunds#new'
post 'refunds, to: 'refunds#create'

然后,无论退款从何处开始,他们最终都会:

http://mydomain/refunds/new

似乎最好让每次退款形成相应的uri上下文......

http://mydomain/organizations/89/invoices/refunds/new
http://mydomain/dashboard/refunds/new

......但复杂性已经失控。有什么想法吗?

0 个答案:

没有答案