EmberJS With PlayFramework 2

Hi all,

I am using Playframework 2/Scala to develop a web site, I would like to use EmberJs but really don’t understand much about how to integrate it with Play (Play might serve an initial view then Ember might request updates getting json results from Play ?) . I don’t want to use any Play plugin because I think that those plugins might not be compatible with the latest versions of Ember or Play (they might be compatible when you start, but not in the future), is it possible ?. So is there anyone who actually develop with Play 2.4 and Ember and could help me with the following questions :

  • templating (how to make Play serve the initial views to Ember, those views containing handlebars tags {{ }} …
  • routing (do we need to declare routes on both sides Play & Ember)
  • authentication (I use simple “authentication” (no securesocial !), is there anything to change ?)

Could you give some code samples ?

Thanks Mike

Hey Mike,

First bit of advice I give to backendy people getting into Ember.js is to never think of their project as ONE app. Draw line and decide how much your Play app will do and how much will Ember do. There may be overlaps, in which case you’ll have to do it on other sides, but separation will save you from constant jumping between two different languages and let you spend your mental energy more effectively.

Templating et all: just use ember-cli that will build your your app to two js files that you will then include like any other js in assets served by backend.

Routing: depends on overlap between ember and backend. If your app is behind authentication and project requires JS, you may as well make one catch-all route in backend telling people to enable JS and handle rest in Ember, but there are situations when you have to provide at support for non-js clients, in which case you have to implement route both in front-end and backend.

We use playframework 2.6 and ember-cli. Basically we created a play plugin that hooks play run and play dist to use ember-cli to either start and serve the output from the ember server during development or to build the ember assets for production.

1 Like

Hi rafalp,

Thanks for your advices, I would like Play to act as a “data provider” meaning that the client side would request for data and Play would send them back via json (restful api). I have just started to look at Ember and would like to know what you mean by “just use ember-cli that will build your app to two js files …”, what are those TWO files ? Do you mean an app developed with Ember is “only” two “big” files containing everything about the logic/templating for the whole client side app ? Thanks Mike

Hi douglasbhill Thanks for your answer, do you know if there is any good tutorial about how to develop with Play and Ember ? Thanks Mike

Hey there!

Ember CLI’s production build is by default two files: vendor.js that contains your app’s dependencies (ember, jquery, etc ect), and app.js that contains your app. That way if you fix your app, you can push new version without forcing your users to redownload less frequently updated dependencies, making process faster for them.

Hello rafalp

Thanks for this informations, I am not used to this kind of structure so I am a little bit lost. I continue viewing videos to get more informations about ember.js …

Hi doublasbhill,

any best practices or learnings about your setup with Ember Cli and Play 2 that you could share with us? I am thinking about project structure, pitfalls, hacks you may have needed so that it works smoothly.

Thx, patrick

PS @ all: When I was googling the topic, this thread was the most solid information I found. Therefore, a blog article or template project of somebody that has engineered a solid solution would be welcome by many and probably also produce some traffic to your blog :wink:

Hi @mikedundee did you get any luck in understanding how it works basically I am also confused with the sort of integration