Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top