Forum: Ruby on Rails map.resource and semi nested resources

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fb49e786662fcd5af6e85217d005a829?d=identicon&s=25 Dave Warnock (Guest)
on 2007-06-30 02:24
(Received via mailing list)

I have the following in routes.rb

  map.resources :districts do |district|
    district.resources :circuits, :name_prefix => 'district_'

  map.resources :circuits

I want full CRUD for circuits at /circuits but only partial CRUD at
/districts/?/circuits (index and new). This is to avoid too many levels
of nesting (there are several more to come).

I have got this fine for the UI (the links take you around exactly as I
want). But the extra urls are still available.

1. How do I detect in the controller show if the url is
/districts/1/circuits/1 which I want to redirect to the un-nested
version at /circuits/1 ?

2. How do I know in index of controller whether I am
/districts/1/circuits (limit to only district 1) or /circuits (list

I guess it will be fairly obvious that I am pretty much a rails newbie.
But I have looked in the Agile bk 2nd ed and as many articles on nested
resources as I can find.


D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-06-30 12:56
(Received via mailing list)
1. If the action was called through the nested route "/districts/1/
circuits/1", params[:district_id] would be set. Otherwise it wouldn't.

2. same here. look for params[:district].

If params[:district]:
  @circuits = Districts.find_by_id(params[:district_id]).ciruits
  @circuits = Circuit.find(:all)
Db303dc84d03a992b33cd3ac978f89ae?d=identicon&s=25 Benjamin Curtis (Guest)
on 2007-06-30 14:45
(Received via mailing list)
The simplest thing you could do is check for the presence of params
[:district_id] in the circuits controller.

Benjamin Curtis -- blog -- build e-commerce
sites with Rails
Fb49e786662fcd5af6e85217d005a829?d=identicon&s=25 Dave Warnock (Guest)
on 2007-07-01 00:20
(Received via mailing list)
Thanks Thorsten & Ben,

Now working as I want.

This topic is locked and can not be replied to.