I am using nested routes in my application (rails 3.2) as follows:
resources :networks do
resources :groups
end
The route for groups show page is as follows
network_group GET /networks/:network_id/groups/:id(.:format)
How can I change the parameters to :network_name and :group_name respectively? Also, I would like to rename the route to group_path (instead of network_group_path ). I would like these changes reflected for all the routes without having to use ‘match’ for the individual routes.
Is it possible to have something like group_path(@network, @group) return ‘/networks/global/groups/all’, where ‘global’ and ‘all’ are both ‘name’ attribute for the respective models. (by default I get the id’s in the url)
We can do that by adding a to_param method in our model
http://railscasts.com/episodes/63-model-name-in-url
In your network and group model, add a #to_param method that returns what you want in the URL (network_name, group_name).
Or else you can use friendly_id gem which gives pretty urls.