Created
July 26, 2012 10:22
-
-
Save solnic/3181379 to your computer and use it in GitHub Desktop.
Determine current route name in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def route_name | |
Rails.application.routes.recognize(request) { |route, _| route.name }.flatten.last.name.to_sym | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
explicit return is needed because
returns a set of nested arrays and not the value of the block. It is also the last executed line in the route_name method.