Re: RESTful URL quesiton

Lee
Wed, 04 Apr 2007 00:42:05 -0000

Maybe design this differently?

map.resources :records do |record|
  record.resources :names
  record.resources :monkeys
end

Note, you can also add over-riding controller name decisions.

record.resources :names, :controller => "record_names"

Of course, you need to be using Rails 1.2 and you need to understand
all the cool things that will give you.

GET /records
POST /records
GET /records/1
PUT /records/1
GET/records/names
POST /records/names
GET /records/names/1

And many other things, but I don''t know if this is what you are
looking for.  You should own Agile Web Development with Rails 2nd
edition as it''s the best reference for Rails.

Good luck!

On Apr 4, 8:00 am, Tyler MacDonald
<google....-oTuY4Vk9bUDG8MNy1oJpyw@public.gmane.org>
wrote:
> Hey everybody,
>
>         I''ve started trying to be a bit fancier with my URLs, and
it''s
> biting me back. :-(
>
>         I am working on a set of controllers to allow people to directly
> manipulate database records... Since they all perform a similar task,
I''ve
> nested them all into the "records" namespace (Records::Name ->
> records/name), etc.
>
>         The main problem: URL recognition.
>
>         I have a top-level "records" controller as well. But it
seems that
> rails wants to divert -everything- to do with records to that controller,
> instead of picking up on sub-controllers (records/name, etc). eg; if I look
> up "records/name" I get "no action responded to
name"... If I try to fill
> out all of the fields (records/name/index/5, say) -- i get
"Recognition
> failed for..."
>
>         If I write a rule like this above the
":controller/:action/:id"
> rule, everythng works:
>
>   map.connect ''records/name/:action/:id'',
>     :controller => ''records/name''
>
>         ... but of course I don''t want to have to write a rule
like that for
> every single sub-controller.
>
>         Is there any way to convince routing to look for the longest
> possible controller name first, so that it always finds
"records/name"
> before just plain ol'' "records"?
>
>         Thanks,
>                 Tyler