Creating a new nested resource
- by Bobby B
I'm working on a basic garden logging application which consists of gardens, plants and planted plants. Each user has one or many gardens, plants are master definitions, and a planted plant can be thought of as an instance of a plant in a specific user's garden.
In my routes.rb file I have the following:
map.resources :gardens do |gardens|
gardens.resources :planted_plants, :has_many => :plant_log_entries, :collection => { :filter => :post, :choose_garden => :post}
gardens.resources :garden_log_entries
end
map.resources :plants
This makes sense to me when retrieving a list of planted_plants in a user's garden, but I'd like to create a planted_plant record from the index of plant. The problem is, a user can have multiple gardens. How can I create a new form for a planted_plant that allows the user to specify which garden should be used?
The current route requires a garden_id - which makes sense for retrieval, but I'd like to supply that as a parameter for creation.
Thanks in advance for any help!