Running js-routes with Rails and Heroku

608 Views Asked by At

Is there any known way to run the js-routes gem on Heroku? The trouble seems to stem from the fact that the routes can't be compiled when the App isn't mounted (because it needs access to the Rails routes), but Heroku won't let you set initialize_on_precompile = true in order to make that possible. I'd really like to use the gem though... I predict it'll save me a ton of trouble down the line. Any ideas?

1

There are 1 best solutions below

0
On

I use workaround. Pre-generate routes in dev env.

Add js routes into development group in Gemfile.

Then fix initializer:

if defined?(JsRoutes)
  JsRoutes.setup do |config|
    config.include = [/item/]
    config.default_url_options = {:locale => I18n.locale}
  end
end

Then run rake js:routes to generate js file. And finally add app/assets/javascripts/routes.js into repo