Forum: Ruby on Rails Problem with model and controller dir having same name?

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.
443a308e12ba2a3082fb6170ca94c2ef?d=identicon&s=25 Ed Wg (ewildgoose)
on 2006-06-06 02:47
(Received via mailing list)
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
4c76f090f2071d34da59c3cf38166587?d=identicon&s=25 Andrew Raines (Guest)
on 2006-06-10 23:04
(Received via mailing list)
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
This topic is locked and can not be replied to.