Getting the default route

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!

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

But this is my default route:
map.connect ‘’, :controller => “dashboard”

Thanks for your reply.

Not that your method doesn’t work. But I would like to do it in the
first way too.

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

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

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:

map.default_route ‘’, :controller => “dashboard”

Hi,
def get_default_action

routes.rb…

map.default_route ‘’, :controller => “home”

views…

link_to “Home”, default_route_url

-philip

Rob B. http://agileconsultingllc.com
[email protected]

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.