Skip to content

Instantly share code, notes, and snippets.

@stoplion
Created August 12, 2020 01:03
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 stoplion/07f73c6ff20a84bcc3c32244cb82474c to your computer and use it in GitHub Desktop.
Save stoplion/07f73c6ff20a84bcc3c32244cb82474c to your computer and use it in GitHub Desktop.
Dump Rails Routes to JSON
```
module AppPathsHelper
def map_routes
routes = Rails.application.routes.routes.map do |route|
{alias: route.name, path: route.path.spec.to_s }
end
white_listed_routes = %w(
new_calc
user_home
user_calc
logged_in_root
logged_out_home
user_calc_embed
calc_search_path
clone_calc
calcs
calc
explore
tag_search
)
routes.reject! {|route| white_listed_routes.exclude?(route[:alias])}
routes.map! do |route|
path = route[:path].gsub!("(.:format)", '')
{**route, path: path}
end
routes.to_json
end
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment