Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Created December 28, 2014 20:04
Show Gist options
  • Save NullVoxPopuli/8c8af217b7404336c72a to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/8c8af217b7404336c72a to your computer and use it in GitHub Desktop.
Route Recognizer to replace the broken Rails 3+'s recognize_path
class RouteRecognizer
include Singleton
ROUTE_LIST = Rails.application.routes.routes.collect{|r| r.path.spec.to_s}
REGEX_ROUT_LIST = ROUTE_LIST.map{|r|
Regexp.new(r.gsub(/\:(.*)id/, "(\d+)").gsub("(.:format)", ""))
}
def self.is_route?(path)
REGEX_ROUT_LIST.each do |regex|
return true if !!(path =~ regex)
end
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment