Hi, I''m using this plugin to get the default controller / action: module ActionController module Routing def get_default_controller ActionController::Routing::Routes.routes[0].requirements[:controller] end def get_default_action ActionController::Routing::Routes.routes[0].requirements[:action] end end end Is this the best way or is there a more simple / easier way to do this? Thanks in advance! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Hi, > > I''m using this plugin to get the default controller / action: > > module ActionController > module Routing > def get_default_controller > > ActionController::Routing::Routes.routes[0].requirements[:controller] > end > def get_default_action > ActionController::Routing::Routes.routes[0].requirements[:action] > end > end > end > > Is this the best way or is there a more simple / easier way to do > this?You could use a named route and then access it with that name... routes.rb... map.default_route '''', :controller => "home" views... link_to "Home", default_route_url -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
But this is my default route: map.connect '''', :controller => "dashboard" Thanks for your reply. On Mar 29, 1:28 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > Hi, > > > I''m using this plugin to get the default controller / action: > > > module ActionController > > module Routing > > def get_default_controller > > > ActionController::Routing::Routes.routes[0].requirements[:controller] > > end > > def get_default_action > > ActionController::Routing::Routes.routes[0].requirements[:action] > > end > > end > > end > > > Is this the best way or is there a more simple / easier way to do > > this? > > You could use a named route and then access it with that name... > > routes.rb... > > map.default_route '''', :controller => "home" > > views... > > link_to "Home", default_route_url > > -philip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not that your method doesn''t work. But I would like to do it in the first way too. On Mar 29, 1:28 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > Hi, > > > I''m using this plugin to get the default controller / action: > > > module ActionController > > module Routing > > def get_default_controller > > > ActionController::Routing::Routes.routes[0].requirements[:controller] > > end > > def get_default_action > > ActionController::Routing::Routes.routes[0].requirements[:action] > > end > > end > > end > > > Is this the best way or is there a more simple / easier way to do > > this? > > You could use a named route and then access it with that name... > > routes.rb... > > map.default_route '''', :controller => "home" > > views... > > link_to "Home", default_route_url > > -philip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> But this is my default route: > map.connect '''', :controller => "dashboard"So change it to... map.default_route '''', :controller => "dashboard" Then in your view do: link_to "Dashboard", default_route_url -philip> Thanks for your reply. > > On Mar 29, 1:28 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote: >>> Hi, >> >>> I''m using this plugin to get the default controller / action: >> >>> module ActionController >>> module Routing >>> def get_default_controller >> >>> ActionController::Routing::Routes.routes[0].requirements[:controller] >>> end >>> def get_default_action >>> ActionController::Routing::Routes.routes[0].requirements[:action] >>> end >>> end >>> end >> >>> Is this the best way or is there a more simple / easier way to do >>> this? >> >> You could use a named route and then access it with that name... >> >> routes.rb... >> >> map.default_route '''', :controller => "home" >> >> views... >> >> link_to "Home", default_route_url >> >> -philip > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there any kind of difference between the two routes? map.connect "/" ... map.connect "" ... Or does Rails render them both as the root? Anyone? [Hope this isn''t threadjacking] RSL On 3/29/07, Philip Hallstrom <rails-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > > > But this is my default route: > > map.connect '''', :controller => "dashboard" > > So change it to... > > map.default_route '''', :controller => "dashboard" > > Then in your view do: > > link_to "Dashboard", default_route_url > > -philip > > > Thanks for your reply. > > > > On Mar 29, 1:28 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote: > >>> Hi, > >> > >>> I''m using this plugin to get the default controller / action: > >> > >>> module ActionController > >>> module Routing > >>> def get_default_controller > >> > >>> ActionController::Routing::Routes.routes[0].requirements[:controller] > >>> end > >>> def get_default_action > >>> ActionController::Routing::Routes.routes > [0].requirements[:action] > >>> end > >>> end > >>> end > >> > >>> Is this the best way or is there a more simple / easier way to do > >>> this? > >> > >> You could use a named route and then access it with that name... > >> > >> routes.rb... > >> > >> map.default_route '''', :controller => "home" > >> > >> views... > >> > >> link_to "Home", default_route_url > >> > >> -philip > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Philip. But then how do I get the seperate controller and action from that default method? I need it to add a seperate class to links with the selected url. On Mar 29, 5:33 pm, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > But this is my default route: > > map.connect '''', :controller => "dashboard" > > So change it to... > > map.default_route '''', :controller => "dashboard" > > Then in your view do: > > link_to "Dashboard", default_route_url > > -philip > > > Thanks for your reply. > > > On Mar 29, 1:28 am, Philip Hallstrom <r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote: > >>> Hi, > > >>> I''m using this plugin to get the default controller / action: > > >>> module ActionController > >>> module Routing > >>> def get_default_controller > > >>> ActionController::Routing::Routes.routes[0].requirements[:controller] > >>> end > >>> def get_default_action > >>> ActionController::Routing::Routes.routes[0].requirements[:action] > >>> end > >>> end > >>> end > > >>> Is this the best way or is there a more simple / easier way to do > >>> this? > > >> You could use a named route and then access it with that name... > > >> routes.rb... > > >> map.default_route '''', :controller => "home" > > >> views... > > >> link_to "Home", default_route_url > > >> -philip--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Perhaps you''ve hinted here at your real problem. Are you thinking
that you want to do something like add a ''class'' attribute to
the
link if it''s the current page?
If that''s true, perhaps this helps:
link_to_unless_current("Dashboard", :controller =>
''dashboard'', :action => ''index'') do
|text|
link_to text, {:controller => ''dashboard'', :action =>
''index''}, :class => ''seperate''
end
If not, perhaps you can explain what you''re TRYING to do rather than
how to accomplish a tiny task that you think is part of the solution.
-Rob
On Mar 29, 2007, at 4:36 PM, LeonB wrote:> Thanks Philip. But then how do I get the seperate controller and
> action from that default method? I need it to add a seperate class to
> links with the selected url.
>
> On Mar 29, 5:33 pm, Philip Hallstrom
<r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:
>>> But this is my default route:
>>> map.connect '''', :controller =>
"dashboard"
>>
>> So change it to...
>>
>> map.default_route '''', :controller =>
"dashboard"
>>
>> Then in your view do:
>>
>> link_to "Dashboard", default_route_url
>>
>> -philip
>>
>>> Thanks for your reply.
>>>
>>> On Mar 29, 1:28 am, Philip Hallstrom
<r...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:
>>>>> Hi,
>>>>>
>>>>> I''m using this plugin to get the default
controller / action:
>>>>>
>>>>> module ActionController
>>>>> module Routing
>>>>> def get_default_controller
>>>>>
>>>>> ActionController::Routing::Routes.routes[0].requirements
>>>>> [:controller]
>>>>> end
>>>>> def get_default_action
>>>>> ActionController::Routing::Routes.routes
>>>>> [0].requirements[:action]
>>>>> end
>>>>> end
>>>>> end
>>>>>
>>>>> Is this the best way or is there a more simple / easier way
to do
>>>>> this?
>>>>
>>>> You could use a named route and then access it with that
name...
>>>>
>>>> routes.rb...
>>>>
>>>> map.default_route '''', :controller =>
"home"
>>>>
>>>> views...
>>>>
>>>> link_to "Home", default_route_url
>>>>
>>>> -philip
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---