# Double directories in url

**URL:** <https://www.ruby-forum.com/t/double-directories-in-url/85091>\
**Category:** Rails\
**Created:** [February 9, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091 "2007-02-09T23:41:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 9, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/1 "2007-02-09T23:41:58Z")

</div>

I’m moved some controllers to  
app/admin/

and add this to the routes

map.connect ‘admin/:controller/:action/:id’

The controllers have the admin prefix :

class Admin::DoSomethingController \< ApplicationController  
…

After the first time accessing the url the ‘admin’ dir is added again.  
The  
result url looks like this:

http://…/admin/admin/do\_something/edit/1

How can this be fixed?? Ideas , anyone?

Rails 1.2.2  
Gems 0.9.2

–  
Best Regards,  
-Larry  
“Work, work, work…there is no satisfactory alternative.”  
— E.Taft Benson

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 9, 2007, 11:54pm UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/2 "2007-02-09T23:54:00Z")

</div>

> …
> 
> After the first time accessing the url the ‘admin’ dir is added again. The  
> result url looks like this:
> 
> http://…/admin/admin/do\_something/edit/1
> 
> How can this be fixed?? Ideas , anyone?

Why not just remove that route? I do the same thing as you but don’t  
have  
that route… just a single route to map “/admin” to the default  
controller in my admin area.

-philip

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 10, 2007, 2:06am UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/3 "2007-02-10T02:06:30Z")

</div>

Philip H. wrote:

> > …
> > 
> > After the first time accessing the url the ‘admin’ dir is added again. The  
> > result url looks like this:
> > 
> > http://…/admin/admin/do\_something/edit/1
> > 
> > How can this be fixed?? Ideas , anyone?
> 
> Why not just remove that route? I do the same thing as you but don’t  
> have  
> that route… just a single route to map “/admin” to the default  
> controller in my admin area.
> 
> -philip

This is correct.

When you move controller into a subfolder like that, the new “url name”  
of that controller is “admin/do\_stuff”. With the route  
“admin/:controller”, the url name of the controller “admin/do\_stuff”  
gets inserted into :controller, producing “admin/admin/do\_stuff”.

So get rid of that admin route and lets ActionController do its thang.

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 10, 2007, 5:38am UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/4 "2007-02-10T05:38:38Z")

</div>

Thanks,  
-Larry

On 2/9/07, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > >
> 
> >

–  
Best Regards,  
-Larry  
“Work, work, work…there is no satisfactory alternative.”  
— E.Taft Benson

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 10, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/5 "2007-02-10T21:18:43Z")

</div>

one quick and dirty way to fix controller problems like these is to  
include the “/” in the beginning of your RAILS methods.

IE:  
normally you may have  
link\_to :controller =\> “admin/main”, :action =\> “do\_something”, :id =\>  
object.id

This would be changed to  
link\_to :controller =\> “/admin/main”, :action =\> “do\_something”, :id =\>  
object.id

and that forces the routing to start at the root.

hope that helps

–jake

Anton A. wrote:

> Philip H. said the following on 02/09/2007 06:02 PM:
> 
> > > …  
> > > controller in my admin area.  
> > > I’m having a similar-but-different problem.
> 
> I’m working on a wiki with webs (books in i2 parlance), so the normal  
> url reads  
> [http://sitename.com/Web/WikiWordTopic](http://sitename.com/Web/WikiWordTopic)
> 
> (do I use “:requirements” to make sure?)
> 
> so the admin interface for doing things that the normal wiki user can’t  
> is
> 
> [http://sitename.com/admin/web](http://sitename.com/admin/web) for the list  
> [http://sitename.com/admin/web/Web](http://sitename.com/admin/web/Web) for a specific web  
> [http://sitename.com/admin/web/Web/WikiWordTopic](http://sitename.com/admin/web/Web/WikiWordTopic) for a specific topic
> 
> and drill down for its attributes.
> 
> Yes, I still have things to sort out like what the urls are for  
> the user to login and return to the access controlled topic (or is that  
> done  
> via cookies), edit a topic … and of course what all that looks like in  
> the  
> mappings…
> 
> 1. Philip could you post the line from your routes.rb, please, to  
> clarify.
> 
> 2. If you move the controllers to app/controllers/admin do you have to  
> add  
> the  
> Admin:: prefix?
> 
> Or, to ask it all another way, is there a different way to  
> compartmentalise  
> both the code and the URL?  
> (such as …/do\_something/1?admin perhaps)
> 
> –  
> If the box says ``Windows 95 or better’', it should run on Linux, right?  
> (Seen on Usenet)

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [February 10, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/double-directories-in-url/85091/6 "2007-02-10T20:32:45Z")

</div>

Philip H. said the following on 02/09/2007 06:02 PM:

> > …  
> > controller in my admin area.  
> > I’m having a similar-but-different problem.

I’m working on a wiki with webs (books in i2 parlance), so the normal  
url reads  
[http://sitename.com/Web/WikiWordTopic](http://sitename.com/Web/WikiWordTopic)

(do I use “:requirements” to make sure?)

so the admin interface for doing things that the normal wiki user can’t  
is

[http://sitename.com/admin/web](http://sitename.com/admin/web) for the list  
[http://sitename.com/admin/web/Web](http://sitename.com/admin/web/Web) for a specific web  
[http://sitename.com/admin/web/Web/WikiWordTopic](http://sitename.com/admin/web/Web/WikiWordTopic) for a specific topic

and drill down for its attributes.

Yes, I still have things to sort out like what the urls are for  
the user to login and return to the access controlled topic (or is that  
done  
via cookies), edit a topic … and of course what all that looks like in  
the  
mappings…

1. Philip could you post the line from your routes.rb, please, to  
clarify.

2. If you move the controllers to app/controllers/admin do you have to  
add  
the  
Admin:: prefix?

Or, to ask it all another way, is there a different way to  
compartmentalise  
both the code and the URL?  
(such as …/do\_something/1?admin perhaps)

–  
If the box says ``Windows 95 or better’', it should run on Linux, right?  
(Seen on Usenet)
