views:

95

answers:

2

In my routes.rb file I have a number of routes. I would like to know which one got matched for any request a user may have made.

For example, in routes.rb you have the following routes :

map.connect ":controller/:action"
map.connect ":controler/:action/:id"

and if I have a controller named a and an action named first, when a user goes to http://whatever/a/first , I would like to see that the :controller/:action route was picked.

Can I do that for any request?

+1  A: 

The closest thing I could find was in the log files. You will see for each request which action of which controller matched. You will see something like this :

Parameters: {"action"=>"show", "id"=>"2", "controller"=>"mycontroller"}

From there, it should be easy,right?

Geo
Yea, if you're watching the logs things get a whole lot easier. My answer still explains how to get it in the browser if you'd prefer that.
kch
+2  A: 

If you just want to know which controller/action you're in, the controller provides controller_name and action_name methods. So you might do something like this:

# in application_controller.rb
before_filter :set_where_am_i
def set_where_am_i
  @where_am_i = "#{controller_name}/#{action_name}"
end

# in views/layouts/application.erb, somewhere in your html
# (here I choose the <title>)

<head><title>Here: <%= @where_am_i %></title>
kch
It works! Thank you!
Geo