Last Updated: February 25, 2016
· vrinek

`rake routes` for Backbone

In case you are developing a Backbone on Rails type of application, one of the things that you will have duplicates of are your routes. Rails provides you with a rake routes command that will display all known routes.

The equivalent of rake routes for Backbone can be achieved with:, function(i){return i.route})

With this, you have a list of regular expressions to try and match to your rails routes.

Example script to make the comparison (needs to be adapted to your needs):

backbone_routes = [

rails_routes = do |route|
  route.path.spec.to_s.sub(/\([^\)]+\)/, '')

backbone_routes.each do |regexp|
  matching_route = rails_routes.find { |route| route =~ regexp }
  puts matching_route || "NO MATCH FOUND - #{regexp.inspect}"

One thing to watch for when copying the Backbone routes (from the browser's JavaScript console) is that [^/] has to be substituted with [^\/] in Ruby to work.