# Problem with model and controller dir having same name?

**URL:** <https://www.ruby-forum.com/t/problem-with-model-and-controller-dir-having-same-name/62552>\
**Category:** Rails\
**Created:** [June 6, 2006, 2:47am UTC](https://www.ruby-forum.com/t/problem-with-model-and-controller-dir-having-same-name/62552 "2006-06-06T02:47:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [June 6, 2006, 2:47am UTC](https://www.ruby-forum.com/t/problem-with-model-and-controller-dir-having-same-name/62552/1 "2006-06-06T02:47:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [June 10, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/problem-with-model-and-controller-dir-having-same-name/62552/2 "2006-06-10T23:04:43Z")

</div>

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
