A typical Rails route like:
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, i.e. something like
/customers/[1,2,3,4,5]
Updated with rationale
The use case:
- This action will be called via Javascript to provide details on selected users. If a user selects 3 customers through the interface, I would like one request to pull info for all 3, instead of having to make 3 separate requests
You could just keep your routes simple:
resources :customers.The list of ids would be considered as the
:idby the routes, and you would get[1, 2, 3, 4]inparams[: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.