Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Created February 27, 2015 15:08
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 pachacamac/3356440fdb14acb0e497 to your computer and use it in GitHub Desktop.
Save pachacamac/3356440fdb14acb0e497 to your computer and use it in GitHub Desktop.
RailsRoutes.js.erb
var RailsRoutes = (function(){
return {
<% Hash[Rails.application.routes.routes.map{|e| ["#{e.name}_path", e.path.spec.to_s.gsub('(.:format)','')]}].each do |name, path| %>
<%= name %>: function(<%= path.scan(/:(\w+)/).map(&:first).join(', ') %>){return <%= "'"+path.gsub(/:(\w+)/){ "'+#{$1}+'" }+"'" %>;},
<% end %>
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment