ruby-on-railsroutesrake

Is it possible to look up a route in Rails by a given url?


Sometimes when customizing a large preexisting Rails platform (e.g. Spree) it would be nice to be able to look up routes by url. Something like:

rake routes URL=/preexisting/url

This obviously doesn't work but is there something like this available in Rails? I've tried looking up the documentation for rake routes but haven't been able to find anything.


Solution

  • If you're using a Unix-based OS (Linux/OSX) you can use grep.

    rake routes | grep /preexisting/url
    

    What this does is takes the output of rake routes, passes (or "pipes") it to grep, which then looks for lines matching "/preexisting/url".