Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.67 KB

README.md

File metadata and controls

54 lines (42 loc) · 1.67 KB

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.