I have question about param name for nested resources in rails routes For example i have:
resources :controller1, param: :controller_id do
resources :controller2
end
and i have routes:
controller1/:controller_id/
...
controller1/:controller_controller_id/controller2/...
...
I want single :controller_id for controller1 I know it's looks bad, but How do this? Thanks!
2 Resource Routing: the Rails Default. Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code.
In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes:
While the default routes and helpers generated by resources will usually serve you well, you may want to customize them in some way. Rails allows you to customize virtually any generic part of the resourceful helpers. The :controller option lets you explicitly specify a controller to use for the resource.
Each method is a request to perform an operation on the resource. A resource route maps a number of related requests to actions in a single controller. When your Rails application receives an incoming request for: it asks the router to map it to a controller action. If the first matching route is:
how about this:
resources :controller1, param: :controller_id do
member do
resources :controller2
end
end
will generate
GET /controller1/:controller_id
GET /controller1/:controller_id/controller2
GET /controller1/:controller_id/controller2/:id
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With