Forum: Ruby on Rails nested resources and collection weirdness

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e7f68f8cf444a3a919a247e562bc464?d=identicon&s=25 Josh Sharpe (crankharder)
on 2009-05-22 15:19
(Received via mailing list)
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?
9e7f68f8cf444a3a919a247e562bc464?d=identicon&s=25 Josh Sharpe (crankharder)
on 2009-05-22 15:25
(Received via mailing list)
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.
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-05-22 15:31
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
marnen@marnen.org
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-05-22 23:09
(Received via mailing list)
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.
This topic is locked and can not be replied to.