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
The problem I’ve had is that if you don’t absolutely path the controller
(
i.e. link_to “Logout”, :controller => “/admin/login”, :action =>
“logout”),
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
up
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 =>
“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.
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.
Yes, but it’s my understanding that link_to uses url_for to create the
link,
and it will be relative to the current controller. It’s not smart enough
to
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
it),
this will be incorrect.
If someone knows better, please enlighten me, because this does indeed
seem to be a bit non-intuative.
Hmmm. Well, I am still new to all of this, but the basic rule of thumb
I
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.
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
this
exact combination yet.
Yeah, that’s basically what I was referring to… I picked it up off of
a
blog post, but I’ve since lost track of where I found it. I was in the
same
situation myself yesterday
Matt
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.