[英]Rails routes to set of resources?
A typical Rails route like: 典型的Rails路线如下:
resource :customer
Sets up routes for index, show, etc. 为索引,显示等设置路线
To access all the customers, I can use the route 要访问所有客户,我可以使用该路线
/customers
To access a single customer, I use: 要访问单个客户,我使用:
/customers/1
Whats the most concise, RESTful way to create a route and controller action that would allow a user to view a set of customers, ie something like 什么是创建路线和控制器操作的最简洁,最RESTful的方式,它可以使用户查看一组客户,例如
/customers/[1,2,3,4,5]
Updated with rationale 更新基本原理
The use case: 用例:
You could just keep your routes simple: resources :customers
. 您只需要保持简单的路线即可:
resources :customers
。
The list of ids would be considered as the :id
by the routes, and you would get [1, 2, 3, 4]
in params[:id]
. 路由列表会将id列表视为
:id
,并且您将在params[:id]
获得[1, 2, 3, 4]
params[:id]
。
Then in your controller, in a before_filter for example, you can check if the id matches a certain regexp (like... /\\[(\\d,)*\\d\\]/
), and if it's the case you can extract the ids. 然后在您的控制器中,例如在before_filter中,您可以检查id是否与某个正则表达式匹配(例如...
/\\[(\\d,)*\\d\\]/
),如果是这种情况,则可以提取ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.