NOTE: This is not the same as Ember Routes and Rails Routes
I have a single-page Ember app that lives on top of a Rails stack. Disregard the need for Rails – it's needed.
My Ember application view lives at /ember_app. I would like to have normal resourceful routes map to Ember routes, like so:
GET /home ~> /ember_app/#/home
GET /account ~> /ember_app/#/account
GET /login ~> /ember_app/#/login
What would be the best approach for this? One thought is:
- Rails
routes.rbsends all requests to a single action,ember_app#indexalong with a parameter containing the name of the Ember route (as withredirect_route: "account"). Notehome,accountandlogindon't need anything data-wise from Rails, just want to redirect to that route in Ember. - The
ember_app#indexaction stores therouteparameter into an instance variable@redirect_route - In
ember_app.html.erb,@redirect_routeis interpolated and stored in a JavaScript variableEmberApp.redirectRoute - In Ember's
application_view.js(or wherever is appropriate) we useEmberApp.redirectRouteto redirect on the client side, accordingly.
Does this approach sound reasonable? We could also have Rails actions for each route, and that route just renders the index action and passes the route parameter. It seems as though, however, there could (should) be a way to map Rails routes to Ember routes programmatically. We don't want to have to duplicate them, once in the Rails routes.rb and in the Ember router.js. Any ideas there?