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 app/controllers/admin/product_controller.rb app/controllers/admin/user_controller.rb app/controllers/login_controller.rb 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" or link_to "Logout", :controller => "/login", :action => "logout" or is there a better way to do that? Thanks! -- Posted via http://www.ruby-forum.com/.
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. On 4/13/06, Eust?quio Rangel <eustaquiorangel@yahoo.com> wrote:> > 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 > > app/controllers/admin/product_controller.rb > app/controllers/admin/user_controller.rb > app/controllers/login_controller.rb > > 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" > > or > > link_to "Logout", :controller => "/login", :action => "logout" > > or is there a better way to do that? > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/fb70874e/attachment.html
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 app/controllers/admin/login_controller.rb and not to app/controllers/login_controller.rb that is the correct path, one level above admin. -- Posted via http://www.ruby-forum.com/.
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. -- Posted via http://www.ruby-forum.com/.
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". Matt On 4/13/06, Eden Brandeis <ebrandeis@gmail.com> wrote:> > 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. > > > On 4/13/06, Eust?quio Rangel <eustaquiorangel@yahoo.com> wrote: > > > > 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 > > > > app/controllers/admin/product_controller.rb > > app/controllers/admin/user_controller.rb > > app/controllers/login_controller.rb > > > > 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" > > > > or > > > > link_to "Logout", :controller => "/login", :action => "logout" > > > > or is there a better way to do that? > > > > Thanks! > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/d4d68076/attachment.html
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. 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 this exact combination yet. On 4/13/06, Eust?quio Rangel <eustaquiorangel@yahoo.com> wrote:> > 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. > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/9f37244a/attachment.html
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. Matt On 4/13/06, Eden Brandeis <ebrandeis@gmail.com> wrote:> > 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. > > 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 > this exact combination yet. > > > > On 4/13/06, Eust?quio Rangel <eustaquiorangel@yahoo.com> wrote: > > > 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. > > > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/1efd338e/attachment-0001.html
Hi! 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 root". -- Posted via http://www.ruby-forum.com/.
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 On 4/13/06, Eust?quio Rangel <eustaquiorangel@yahoo.com> wrote:> > Hi! > > 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 > root". > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/d5fbdd84/attachment.html