This talk covers the options for structuring concurrent Rails and Ember development, strategies for creating backend APIs that work well with Ember apps, and some innovative ideas around deploying your Ember and Rails apps into production.
Model Data flows down from models via bindings Events flow up from view layer to the router Router updates models & controllers based on events Data Flow in Ember
your Ember app from your Rails app. Proxy in development. ★ Use any build tools, including grunt, gulp, brunch, or broccoli. ★ ember-cli is likely to be the future, still a work-in-progress
apps, controllers make instance variables available to be rendered using ERB ★ In a Ember+Rails app, controllers instead serialize these “instance variables” into JSON and make it available to Ember to render 23
your API if your Ember app is served off the same domain as your Rails app is ★ If you must cross domains, check out the rack- cors gem. 30 https://github.com/cyu/rack-cors
deploy as Rails app changes Rails server Dev or CI API requests dynamic Rails pages HTML for JS App JS for JS App CSS, Images for JS App AWS Cloudfront Deploy Rails app code, HTML, JS, CSS, images
(AWS S3) Rails server Dev or CI Deploy JS, CSS, images (additive) API requests dynamic Rails pages HTML for JS App JS for JS App CSS, Images for JS App Deploy HTML AWS Cloudfront Deploy Rails app code https://speakerdeck.com/lukemelia/lightning-fast-deployment-of-your-rails-backed-javascript-app
the client, am I doing double the work?” (cont.) 37 ★ As Andre Malan said, “Your front end is not your back end” ★ Your Rails and Ember apps have separate responsibilities. Duplicated work on client and server is unusual.
Ember controller?” 38 ★ A Rails controller is responsible for doing some queries or work and initiating the rendering of JSON or HTML ★ An Ember controller is more akin to a “view model” or “presenter” in Rails land. It is responsible for presenting bindable data to templates for rendering by proxying models and maintaining non-model state and computed properties.
39 ★ No. ★ Rails routes are typically based on REST principles. ★ Ember routes map to the URLs a users sees as they move through the app and are nested to match the nested structure of the UI.
Separate log-in page. Standard Rails cookie-based auth. (Must be on same domain.) ★ More complicated: Token-based authentication. Login with username / password, receive bearer token. Send bearer token in Authorization header with all API requests.
Most Ember apps have a UserController or MeController to allow routes and other controllers access to information about the current user. https://github.com/simplabs/ember-simple-auth