I’ve previously asked a question related to this topic as well and with the aid of that question I’ve found the name of exactly what I wanted: “bound parameters”.
I have managed to create a routing like “user/:id/dosomething” by adding a member to the routes.rb. However, this type of URL is not the solution I was looking for.
My question is, how do you provide the ‘user/dosomething/:id’ to match with action user’s dosomething action with id sent as parameter?
Here is the section I’ve read in order to get the idea:
3.1 Bound Parameters
When you set up a regular route, you supply a series of symbols that
Rails maps to parts of an incoming HTTP request. Two of these symbols
are special::controllermaps to the name of a controller in your
application, and:actionmaps to the name of an action within that
controller. For example, consider this route:get ':controller(/:action(/:id))'If an incoming request of
/photos/show/1is processed by this route
(because it hasn’t matched any previous route in the file), then the
result will be to invoke the show action of thePhotosController, and
to make the final parameter"1"available asparams[:id]. This route
will also route the incoming request of/photosto
PhotosController#index, since:actionand:idare optional
parameters, denoted by parentheses.
You can add a custom route:
This will route HTTP
GETrequests that match the URLuser/dosomething/:idto theUsersController‘sdo_somethingaction. The:as => 'do_something_user'part names the route, so that you can usedo_something_user_pathanddo_something_user_urlhelpers to generate the URLs.For more information on routing, see Rails Routing from the Outside In.