Forum: Ruby on Rails Controller paths

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eustáquio R. (Guest)
on 2006-04-13 16:31
Hi there.

Suppose I create some controllers like

ruby script/generate controller Admin::product add remove
ruby script/generate controller Admin::user add remove
ruby script/generate controller Login login logout

the directory structure will be


Now suppose I need some links with link_to from the product and user
controller to the login controller. Does I need to use some paths like

link_to "Logout", :controller => "../login", :action => "logout"


link_to "Logout", :controller => "/login", :action => "logout"

or is there a better way to do that?

Eden B. (Guest)
on 2006-04-13 18:30
(Received via mailing list)
In my experience you need to use:

link_to "Logout", :controller => "admin/login", :action => "logout"

There may be another way to do it, but I haven't found it yet.
Eustáquio R. (Guest)
on 2006-04-13 18:38
Hi Eden!

> In my experience you need to use:
> link_to "Logout", :controller => "admin/login", :action => "logout"

On this case, I'm creating a link from admin to login. Admin is *under*
login, so I need to refer to a level up there. If I use "admin/login" I
think it will try to refers to


and not to


that is the correct path, one level above admin.
Eustáquio R. (Guest)
on 2006-04-13 18:46
Hi again.

> On this case, I'm creating a link from admin to login. Admin is *under*
> login, so I need to refer to a level up there.

Sorry, I made some confusion here. What I'd like to say is login is
*above* login, so I need to refer to a level up the admin controller.
So, from the admin/product controller, for example, create a link to the
login controller, one level up.
Matt W. (Guest)
on 2006-04-13 19:00
(Received via mailing list)
The problem I've had is that if you don't absolutely path the controller
i.e. link_to "Logout", :controller => "/admin/login", :action =>
it won't work if you're using "link_to" within any of the "admin"
controllers. It will prepend an extra "admin" to the link, so you'll end
with "/admin/admin/login".

If you're linking to the login controller within one of the admin
controllers, you can just use :controller => "/login", :action =>

Eden B. (Guest)
on 2006-04-13 19:04
(Received via mailing list)
Hmmm.  Well, I am still new to all of this, but the basic rule of thumb
use is that :controller should be set as if you are always in the
controllers folder regardless of where the call is coming from.  Rails
routing should take care of determining the exact html link.

So I *think* that:

link_to "Logout", :controller => "login", :action => "logout"

should work even if you are calling it from views/admin/product.  I
would be
interested in hearing if this assumption is wrong since I haven't tried
exact combination yet.
Matt W. (Guest)
on 2006-04-13 19:10
(Received via mailing list)
Yes, but it's my understanding that link_to uses url_for to create the
and it will be relative to the current controller. It's not smart enough
figure out that you have a login_controller that's above the current
directory path. Instead it makes the link relative to the current
controller. If you're in a sub-controller (or whatever you want to call
this will be incorrect.

If someone knows better, *please* enlighten me, because this does indeed
seem to be a bit non-intuative.

Eustáquio R. (Guest)
on 2006-04-13 20:25

Seems that if I use

link_to "Logout", :controller => "/login", :action => "logout"
link_to "Logout", :controller => "/admin/user", :action => "add"

it works ok. The first / works as, let me call this way, the "controller
Matt W. (Guest)
on 2006-04-14 00:37
(Received via mailing list)
Yeah, that's basically what I was referring to... I picked it up off of
blog post, but I've since lost track of where I found it. I was in the
situation myself yesterday :)

This topic is locked and can not be replied to.