Problem with model and controller dir having same name?

After a rather frustrating couple of hours I finally realised that if
you generate controllers under a subdirectory, eg /admin/book,
/admin/account, etc and you also generate a model with name “Admin”,
then rails gets confused and prints a really useless error:

Recognition failed for “/admin/account”

This is with rails 1.1.2. Can someone please explain:

a) Why this happens
b) How to work around this if I really, really want to have both my
controllers under an “admin” subdir and also require a model with the
same name?

Grateful for any insight/workarounds

Ed W

Ed W wrote:

a) Why this happens
It entirely depends on config/routes.rb. I assume that since
you didn’t mention it, you’ve left it alone. In that case,
“:controller/:action/:id” will get invoked for a request to
`/admin/account’, and you probably do not have either of:

app/controllers/admin_controller.rb
app/views/admin/account.rhtml

because you instead have:

app/controllers/admin/account_controller.rb

and perhaps:

app/views/admin/account/index.rhtml

Right?

b) How to work around this if I really, really want to have
both my controllers under an “admin” subdir and also require
a model with the same name?

There’s no limitation to work around – Rails doesn’t care
about app/models/* when routing requests. You only need to
tell it how to handle those non-standard URLs:

map.connect “admin/account/:action/:id”, :controller =>
“admin/account”
map.connect “:controller/:action/:id”

This way, even if you have an AdminController class, Rails
will still look for Admin::AccountController for
`/admin/account/*’ URLs.

-Drew