I am pretty sure there is and answer out there.. But I can’t seem to find what is the cleanest way to do it, and I am just starting playing around with Ruby and Rails 3.1.
I have a Client model and a Project model.
I’d like to have a button on the client#show view that leads to a project#new where there is no need to input the client_id.
Furthermore the project#new should still be accessible on his own and ask for the client_id if it is not available.
Any help appreciated!
Thanks
Take a look at nested resources:
http://guides.rubyonrails.org/routing.html#nested-resources
Using that take care of the passing through of the parent ID. You can have a route that goes directly to project#new as well and then you’ll just need to handle whether to ask for the client ID in the view depending on whether it is already defined.