Ember Rails Devise Demo
This app is working example of using Ember with Rails and Devise. As Ember matures, I hope to expand it with other common Ember paradigms.
The running app can be viewed at: http://emrailsdevise.herokuapp.com/
Disclaimer: Ember.js is still very new and in flux, I am far from an expert, and documentation, while improving, is still not comprehensive. Code here should be viewed as possible ways to do things, not the definitive way. Welcome input on improvements.
- User Login and Registration using Devise
- Illustrates basic usages of Ember components like routes, controllers, views, templates, state managers.
Currently runs on Ember.js 1.0 RC1
To run the app:
(clone or fork the project) $ bundle install $ bundle exec rake db:create $ bundle exec rake db:migrate $ bundle exec rake db:seed (will create a test user, or just register a new one from the app) $ rails server
In traditional Rails apps, pretty much every user click results in an HTTP request. The server processes the request, and generate an HTML page it returns to the client. This happens even for tasks the client has the data to handle, such as sorting a list on the page.
In the Ember/Rails world, Ember handles client interactions and page display. Rails may serve the initial page, as done here (also can be done by an HTTP server like nginx). Then it waits for AJAX requests and responds with JSON.
Under this architecture, the Rails components which pertain directly with the client are:
- a bare-bones layout (views/layouts/application.html) which includes the Ember client and css
- a blank root page (here view/home/index)
- a root controller (here HomeController)
- routes defined in routes.rb
- serializers, here using the active_model_serializer gem for packaging (in the app/serializers directory)
Devise with AJAX
When using Devise with AJAX you must add:
respond_to :html, :json
to the appropriate Rails controller(s). In this app, its been added to ApplicationController. More here.
There are a couple of capybara-webkit tests up. The first tests a registration-logout-login cycle. Was going to separate these out, but the standalone login test doesn't work for some reason (even though works in development). Appreciate if anyone can figure this out.
The tests here are for reference to show how to set up Konacha and far from comprehensive.
Setup is easy:
- Add the gem to your gemfile (and run bundle install)
- Write some tests
- Run the task: bundle exec rake konacha:serve. This will startup up a server running, by default" on port 3500.
- Go to localhost:3500 to see test results
See the Konacha github page for detailed info.
Most immediately, validations and tests are sparse. Plan to add features as time goes by.
Other Ember.js/Rails Resources
Demos and Learning Resources
The official guides:
Definitely worthwhile, though found it easier to watch it at 2X speed as recitation a tad slow
I found both of the following demos helpful (and new ones appearing all the time):
Think HTML/Handlebars too verbose? Alex Matchneer is developing a Slim-like templating solution:
Copyright 2013 Michael Madrid under the MIT License