How to integrate EmberJS incrementally into an rails web app?

Viewed 62

we're working on our opensource password manager cryptopus https://github.com/puzzle/cryptopus. since our last release we integrated emberjs and are updating one component after another from classic rails webapp to emberjs. For now, we used locationType: "hash" to trigger emberjs parts.

one challenge we're facing now is to make sure the URLs are still the same after moving the UI components to emberjs. So we should get rid of "hash"-URLs for emberjs and still be able to call some legacy rails webapp URLs.

is there a way to ignore routes in emberjs and sending the request to the backend? any other ideas to make an incremental integration of emberjs possible? It would be OK if the SPA would be re-initialized after coming back from an class rails webapp URL.

some example routes:

/session/new -> send to rails backend
/teams -> handle by emberjs
/teams/42 -> handle by emberjs
/admin/users -> send to rails backend

it would be also possible to add a prefix for all emberjs handled routes like: /app/teams, /app/teams/42

1 Answers

we found a pretty simple solution for the problem.

  1. in config/environment.js: removed rootURL, locationType: "auto"
  2. configured all required routes in emberjs
  3. created an frontend controller in rails which serves the ember files on first request

so now, some frontend parts of the app run with ember, others still with rails. the ember router doesn't care about URLs that are not configured. Pretty nice solution :)

have a look at https://github.com/puzzle/cryptopus to see the complete solution.

Related