I have an e-commerce web site written in Rails 3.2.8 which sells tickets for music events. So far I’ve been using simple RESTful routes in the application:
/ => default route: /events
/events
/events/1
/events/1/new
/events/2
...
All events used to happen in the same place, but from now on there’s going to be two places, let’s say “Morumbi” and “Maracanã”. Place is a model in the application, and it’s a very important distinction between the events. So I’d like to make the place name a part of the path, and have routes like this:
/ => default route: page to choose place
/morumbi => same as /morumbi/events
/morumbi/events/1
/morumbi/events/1/new
/maracana => same as /maracana/events
/maracana/events/2
...
Although I know how to do that using the #match method, I have already a good number of routes created with the much more maintainable #resources method, and I’d like to keep them.
Do you know a solution avoiding the use of #match?
You need to use the
#scopemethod:So
GET /morumbi/events/1will callEventsController#showwith parametersid: '1'andplace_name: 'morumbi'.