Robert Strohmeyer
Robert Strohmeyer

Reputation: 512

What's the best way to port my Rails 3.2 app to Ember.js?

I have a fairly simple Rails 3.2 app deployed to Heroku, and I'd like to port it into Ember to cut overhead and streamline the app before I continue building it out further. Can anyone offer general guidance on how best to approach this to keep my existing Postgres user data intact?

I'm very new to Ember, and just getting started, but I'd like to start thinking specifically about solving this problem before I get too much further down the road.

FWIW, I'm vaguely aware of ember-rails (https://github.com/emberjs/ember-rails), but my current instinct is that I'd like to move off of Rails entirely to keep the app lean. Feel free to comment on why I'm wrong about that. :)

Upvotes: 1

Views: 154

Answers (1)

Miguel Madero
Miguel Madero

Reputation: 1948

We've a Rails 4 app with a jQuery front-end and we're slowly adopting Ember. This is probably an open question without a single right answer, so I'll provide just some guidance.

First, I'll start by saying that Ember and Rails solve different problems. Ember isn't a Rails replacement, but rather part of a bigger system where Rails is one component, Ember another, just like your Database is another part. That said, using Ember simplifies and maybe removes the need to do certain parts in Rails, so there is some overlap. If you were to remove Rails, you will likely have to replace it with something equivalent.

Now a few ideas or approaches:

  • Side App/Page. Find a new and small functional area that could be separate from your main app that can be done end to end with Ember. For example on an e-commerce site, looking at your Order History. Doing something separate you can start getting some benefits without having to re-write all the existing functionality or risking to break something. You can also start from scratch without worrying about your legacy code.
  • Rewrite it all. Obviously the drawback is time here. You could start by copying your generated HTML, moving it to Handlebars and change the dynamic parts of it into bindings ({{name}}). Plan your models and use fixtures to get it all working. Create some controllers to add the flow and finally replace fixtures with calls to a new Rails API.
  • Portion of a Page. This one is tricky because Ember kinda like to own the full page, but it might be the best way to go since the rewrite takes long and there might not be a Side App with enough value to work on. If you do this, you will have to disable the history in Ember, set the rootElement to the portion of the page you're refreshing. If there're interactions between this section and other sections of the app, you might need to make Ember generated markup compatible with the legacy javascript code in the page (e.g maintain data-attributes used for behavior).

Also, if you're using TurboLinks and can't disable it until you're on Ember, you will have to make sure ember loads properly on turbolink's page lifecycle. See TurboLinksHackForEmber

Upvotes: 1

Related Questions