Discussion Forums
- Topic List
- Most Recent Posts
- Sign In for more options
I have a conference application in the works that has many attendees and each attendee could potentially have one presenter. In my routes file I have
map.resources :conferences, :has_many => :attendees
to nest attendees under conferences for /conference/1/attendees/2 urls. The second step is that each attendee potentially has one presenter. I have not yet figured out how to doube next resources. I currently have
map.resources :attendee, :has_one => :presenter
but that gives me /attendee/1/presenter/1 urls, without first nesting attendees under conferences. Is this possible? Is it a good idea, besides the hideously long urls?
The flow of the application is as follows. A visitor can register for a conference as an attendee. Once their registration is complete, they can optionally register to present at that conference. In the end, I need the attendee linked to the presenter and the attendee and presenter both linked to the conference.
Since the attendee registration is completed before anyone can register as a presenter, I can extract the conference_id field from the attendee object. So far, I've used
/attendees/4/presenter/new
urls in order to retrieve the attendee object, create the new presenter object, set the presenter's conference_id based on the attendee's conference_id, and then save the new presenter object.
This seemed to work relatively well, but I'm not 100% set on this approach. Any suggestions?
Without getting tangled in the debate over the value of nested resources, here is how to nest resources arbitrarily. Using your example:
map.resources :conferences do |conference|
conference.resources :attendees do |attendee|
attendee.resource :presenter
end
end
