Reputation: 3489
I'm using the default resource in my routes.rb to add clients to my applications via resources :clients
. But I'd like to be able to access that new
page of clients via a group_id aswell.
So I want access like /clients/new/
and as clients/new/1/
or something.
I've tried adding my group to my path like new_client_path(group)
but it gives me a .3 and showing the params shows that the 3 is called 'format'.
So, Long story short: How can I get a group_id to my clients/new/
page?
Thanks in advance
Upvotes: 0
Views: 27
Reputation: 51171
You can use nested resources:
resources :groups
resources :clients
end
Now to get new client form with group id set you just need:
new_group_client_path(group)
assuming, of course, that group
variable holds an Group
instance.
If you don't want to use nested resources, you can set group_id
this way
new_client_path(group_id: group)
Upvotes: 1