No commit activity in last 3 years
No release in over 3 years
Make rails route available via window.Routes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 4.0.0

Runtime

>= 0
 Project Readme

Rails::Routes::Js::Utils

Make rails route available in Javascript via window.Routes.*_path() and Array window.AllRoutes This also generates plist file for iOS in /assets/rails-routes-js-utils.plist

Installation

Add this line to your application's Gemfile:

gem 'rails-routes-js-utils'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-routes-js-utils

Add this to application.js

//= require rails-routes-js-utils

Usage

Routes.blog_post_path(123)
Routes.blog_post_path({id: 123})
Routes.blog_posts_path()

for (var i=0; i<AllRoutes.length; i++){
    var route = AllRoutes[i];
    var host = document.location.hostname;
    var pathname = document.location.pathname;
    if (route.path.test(pathname) && route.host.test(host)) {
        // Matched route
        console.log(route);
        var controller = route.reqs.controller;
        var action = route.reqs.action;
        var parts = route.reqs.parts; 
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request