1
votes

I'm currently using Ruby on Rails and EmberJS for a project. The Rails app is an ecommerce store and will need ~10 models to be loaded initially. I was thinking of using Gon to pass the models down as json on initial page load.

I'm thinking of using the ember cli to make one project, and, of course, ruby on rails to make the API.

If I make the application separate, how does one do initial data load? When it comes to deployment, how do you make sure that everything runs off of one rails server (thinking Heroku)?

1

1 Answers

2
votes

If you're only using Rails (without Ember CLI), you could render the gon object in the application layout per gon's instructions and just pluck your data off of the gon global. Good place to do this might be your application route in Ember:

// routes/application.js

export default Ember.Route.extend({
  model: function() {
    return gon.myDataSet;
  }
});

However, I would recommend using Ember CLI, which if you do, cuts your rails application layout (and thus gon) out of the equation. Instead, simply open up json endpoints on your rails application where you can then fetch it in your Ember application:

// routes/application.js

export default Ember.Route.extend({
  model: function() {
    return Ember.$.getJSON('/path/in/rails/app');
  }
});

Then while you're in development run your rails server in one terminal, and then run your ember server (from the CLI directory) with the proxy option:

$ ember server --proxy http://localhost:3000

As for deploying, that's a whole can of worms, but check out ember-cli-deploy as it aims to be the one stop shop for deploying ember apps.