Skip to content

Instantly share code, notes, and snippets.

@mmmpa
Last active August 29, 2015 14:10
Show Gist options
  • Save mmmpa/2f40c97755e0a40505a6 to your computer and use it in GitHub Desktop.
Save mmmpa/2f40c97755e0a40505a6 to your computer and use it in GitHub Desktop.
routes = Rails.application.routes.routes.map do |route|
path = route.path.spec.to_s.gsub(/\(\.:format\)/, "")
params = path.scan(/:([a-zA-Z_]+)/).flatten.collect(&:to_sym)
verb = %W{ GET POST PUT PATCH DELETE }.grep(route.verb).first.downcase.to_sym
action = route.defaults[:action]
controller = route.defaults[:controller]
{
#path: path,
verb: verb,
action: action && action.to_sym,
controller: controller,
params: params
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment