Created
August 12, 2020 01:03
-
-
Save stoplion/07f73c6ff20a84bcc3c32244cb82474c to your computer and use it in GitHub Desktop.
Dump Rails Routes to JSON
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
``` | |
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