No commit activity in last 3 years
No release in over 3 years
Creating a Guard task to auto-regenerate app/javascript/packs/routes.js file when config/routes.rb is updated.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

JsRoutesWatcher

Plugin for Ruby on Rails which utilise js-routes gem to work with webpacker.

Using modern JS-frameworks such as Vue or React, you have to move all rails-generated routes to javascript. Then you'll be able to do this:

const login_path = Routes.api_login_path()

js-routes gem gives you the ability to export rails routes to standalone js-file.

But how to do this automatically? There's gem you're watching on comes to play.

Every time when config/routes.rb is updated Guard task will regenerate app/javascript/packs/routes.js file. And all you have to do – is to import it in your project js-packs.

import './routes.js'
// Then
Routes.api_login_path()

Installation

All you need to start using plugin is to:

  1. Install gem. Add this line to your application's Gemfile:
gem 'js_routes_watcher', github: "codemotion/js_routes_watcher"

And then execute:

$ bundle
  1. Create Guardfile in the root of the project and fill it with:
guard 'rake', :task => 'js_routes_watcher:generate' do
  watch(%r{^config/routes.rb})
end

And then save file.

  1. Be shure what you're using webpacker gem and starting it with Foreman or Overmind.

  2. Procfile must have the following line to start Guard task in background:

guard: bundle exec guard

Contributing

You're free to contribute via pull requests.

License

The gem is available as open source under the terms of the MIT License.