Skip to content

Instantly share code, notes, and snippets.

@YurySolovyov
Last active August 26, 2019 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YurySolovyov/682c35ffabecc56fe5528075a4577567 to your computer and use it in GitHub Desktop.
Save YurySolovyov/682c35ffabecc56fe5528075a4577567 to your computer and use it in GitHub Desktop.
module ActionDispatch
module Routing
class HashFormatter
attr_reader :result
def initialize
@result = {}
end
def section_title(title); end
def section(routes)
routes.each { |route| incorporate_route(route) }
end
def header(routes); end
def no_routes(routes, filter); end
private
def incorporate_route(route)
name = route[:name]
return if route.empty? || name.empty?
prepared_route = route.without(:reqs, :name).merge(
path: route[:path].remove('(.:format)')
)
result.merge!(name => prepared_route)
end
end
end
end
require 'action_dispatch/routing/inspector'
module ApplicationHelper
def client_routes_json
inspector = ActionDispatch::Routing::RoutesInspector.new(
Rails.application.routes.routes
)
inspector.format(ActionDispatch::Routing::HashFormatter.new).to_json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment