# Nested resources and collection weirdness

**URL:** <https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573>\
**Category:** Rails\
**Created:** [May 22, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573 "2009-05-22T15:19:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [May 22, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573/1 "2009-05-22T15:19:49Z")

</div>

I need the route /events/:event\_id/races/edit, so:

map.resources :events do |event|  
event.resources :races, :collection =\> {:edit =\> :get}  
end

Which produces this:

edit\_event\_races GET /events/:event\_id/races/edit(.:format)  
{:action=\>“edit”, :id=\>/[^/.?]+/, :controller=\>“races”}

This is exactly what I expected except for the weirdness over at :id

As a result, edit\_event\_races\_path(@event) or edit\_event\_races\_path  
(@event.id) is blowing up in my face:

edit\_event\_races\_url failed to generate from  
{:controller=\>“races”, :action=\>“edit”, :event\_id=\>#\<Event id: 1,  
name: “Ride Sally Ride”\>, :id=\>/[^/.?]+/}

Am I doing something wrong here?

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [May 22, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573/2 "2009-05-22T15:25:40Z")

</div>

I’m aware that the route /events/:event\_id/races/:race\_id/edit exists  
but that is not what I want. My goal is to edit all the races  
collectively, not individually, so I need the route mentioned above.

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [May 22, 2009, 3:31pm UTC](https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573/3 "2009-05-22T15:31:24Z")

</div>

Josh Sharpe wrote:  
[…]

> As a result, edit\_event\_races\_path(@event) or edit\_event\_races\_path  
> (@event.id) is blowing up in my face:
> 
> edit\_event\_races\_url failed to generate from  
> {:controller=\>“races”, :action=\>“edit”, :event\_id=\>#\<Event id: 1,  
> name: “Ride Sally Ride”\>, :id=\>/[^/.?]+/}
> 
> Am I doing something wrong here?

So it would seem. You’re passing an Event object where Rails is  
apparently expecting an ID. Note what :event\_id holds.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [May 22, 2009, 11:09pm UTC](https://www.ruby-forum.com/t/nested-resources-and-collection-weirdness/168573/4 "2009-05-22T23:09:56Z")

</div>

Sounds like what you’re after is an “event/#/index” that:

1. paginates the associated “races” into a
2. table that can be editted by  
2a) individual field  
2b) selected groups of fields
3. with a save that only saves modified “race” records

I may be wrong but that doesn’t sound like a restful route to me.
