Cannot get it to work #98

Closed
manuelmeurer opened this Issue Feb 24, 2014 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

manuelmeurer commented Feb 24, 2014

I'm having trouble getting this to work.

I have a Rails v4.1.0.rc1 app with an application namespace and an admin namespace, so I want to generate AppRoutes and AdminRoutes.

I use js-routes v0.9.7 and this is my initializer (just the AdminRoutes for now)

# config/initializers/js_routes.rb
require 'js_routes'

JsRoutes.generate! \
  file:      File.join('app', 'assets', 'javascripts', 'admin_routes.js'),
  namespace: 'AdminRoutes',
  include:   /admin/

Should I then use = require js-routes or = require admin_routes?

When I use = require js-routes, AdminRoutes is undefined and Routes contains all routes, not just the admin ones: http://screencast.com/t/uKGKH945aT0n

When I use = require admin_routes, Routes is undefined and AdminRoutes just contains options but no routes: http://screencast.com/t/6pHezoqU7

Both cases are not what I expect.
The file app/assets/javascripts/admin_routes.js is generated in both cases but apart from the boilerplate code doesn't contain any routes.
Very confusing all that. What am I doing wrong?

Owner

le0pard commented Feb 24, 2014

Why do you put generation of js files in initializer? If you need both routes, just add this in your js file with .erb prefix - assets pipeline will do all work. Example:

/* app/assets/javascripts/routes.js.erb */
<%= JsRoutes.generate(namespace: "Routes", exclude: [/admin/]) %>
<%= JsRoutes.generate(namespace: "AdminRoutes", include: /admin/) %>
Contributor

manuelmeurer commented Feb 24, 2014

That works, thanks! But where would you use JsRoutes.generate! if not in an initializer?

Owner

le0pard commented Feb 24, 2014

@manuelmeurer for example, in rake task: if you need deploy routes, but impossible to load env for assets pipeline (like on heroku). Or you just need generate static routes once: again or rake task, or some Ruby script.

Contributor

manuelmeurer commented Feb 24, 2014

Ok, the README is not very clear on that, I will submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment