#408 Ember Part 1 pro
Ember.js is a javascript framework for making rich client-side applications. In the first part of this two part series I show how to setup templates, controllers, and routes.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
For an indented Ember-compatible alternative to Handlebars templates, you can try Emblem.js
+1, Emblem.js is awesome!
Thanks for mentioning this, been looking for a HAML-like engine for JS - it does look great.
You can also go with Slim which does not have the problems Haml has with interpolation of Handlebar templates. Stuff is still rendered on the server side then.
+1, Embelm.js can take the place of slim.
Thanks for this, it made me happy that I went with AngularJS instead of Ember in my last project.
+1
Mind sharing your thoughts?
+1 to sharing thoughts
+1
Me too. I'm just starting with Angular, but already can't imagine myself doing something in Ember or Backbone :)
Agreed. This gave me more reasons to use angularjs :).
+1
+1
Thanks for the fantastic research work Ryan. Now I know. Angular it is :)
Yes...Angular it is!!! Congratulations Ryan
I am in the same boat. Have been researching Ember vs Angular vs whatever. Seems Angular is going to be the winner.
+1
+1.
AngularJS is easier to understand even for frontend developers .
Also very suitable for prototyping
I don't think the number of screencast matter in this case. I think ember was very clearly presented in this one. Can't wait to see persistence in the next.
AngularJS is easier (actually way easier to understand) but Emberjs pays off in the end (in my opinion). Took me two weeks to learn most of what i needed from it and create a web gallery/photo store app front end (to sell files and prints) that runs very smoothly even in most 2-3 year old android and apple devices.
That being said, i can assure you... it was painful and frustrating, ember-data still needs a LOT of work, documentation can be confusing and outdated in some cases... As the framework changed a lot on the last few months a lot of the things you can find on stackoverflow are outdated...
On the other hand, once i started grasping the concepts of it, it just started to make perfect sense and now i love it.
Just my 2 cents!
Did you spend the same two weeks learning AngularJS? Makes sense that if you spend two weeks on something then it will start to make perfect sense. It's just because you are learning it. ;-)
Might want to look at the blog post I just wrote on building a small sample app. It's going to be a series and build upon that first post from week to week.
http://www.devmynd.com/blog/2013-3-rails-ember-js
Liked the Active::Record stuff on that blog so I've bookmarked this for later reading.
Thanks
+1
+1
For what it's worth, Ember doesn't show its relative strength when putting together toy apps. Would be nice to see a much more complex example and some commentary on how the two frameworks scale differently.
Very true and the frontpage says it all.
This is exactly the main difference in choosing Ember over Angular or Backbone. When you get into large applications like im working on, Angular and BB both become more difficult to manage. Zombie memory from events and views becomes a manual problem. Angulars dirty checking becomes more of a problem with large apps. And Nested views is a PIA compared to Ember. I find that for small apps Angular is probably a better choice. But if you are building a large web app Ember becomes the much better choice.
http://jsperf.com/angular-vs-knockout-vs-ember/99
I also find it kind of sad that there seems to be this love hate thing with JS frameworks. I think there are great things in both and, depending on the job, either could be a best choice.
Thanks again Ryan for the great stuff!
+1
Meteor 15min, Angular 16min, backbone 32min and Ember 25min+. Meteor Wins!
+1
Is anyone using Spine? Would love to hear some comparison between Spine and Angular.
+1
+1 for sure!
I was watching all the gotchyas of setting up a controller and action and objects and applying properties and outputting things into the view and going, "Whoa! Why!? Just use AngularJS." haha
I'm not sure what the advantage of Ember.js is yet—I'm sure there is one—maybe it just feels more comfortable to die-hard Rails fans.
I think that the thing that confuses me with all of these javascript frameworks is, why use Rails at this point? I understand the difference between client side and server side frameworks, but all of these seem to be really intrusive to the Rails framework. Instead of using the application controller and returning a JS on
remote: true
or having the coffeescript monitor a click, we have to go through this entirely different framework to accomplish a simple task. Does anyone else feel my pain?Yes. It is why I'm learning Node and keeping my eye on Dart. One language for server and client.
Dart is a FAIL. The last thing we need to see is a revival of client side browser programming fragmentation ala the VBScript days. JavaScript isn't going anywhere for the foreseeable future.
Exactly. It is not easy to start writing applications in some js framework while jQuery suits most use cases really well and it so easy to start with. But I found that Angular can solve some tasks in a way that easier to implement than jQuery equivalent. Most important, you don't have to setup full-stack application for Angular. Just include it and start using.
Do you mind elaborating on which task you find Angular is better at than JQuery? I'm trying to figure out whether to use Angular or even Ember for some stuff, but I'm not sure how to integrate these into an app that's already built on rails. I find it much easier to use JQuery along with Handlebars for templating in such cases.
Maybe its just me, but I don't see Angular working this way. What I mean is, it doesn't seem to be the right technology to use to "add js" functionality. jQuery is great for that. But these javascript frameworks make so much more sense when you build something for the client side FIRST.
You want to write your app in angular/ember and THEN use Rails or Sinatra (or...) for persistance, validations, and logic the user doesn't have to or shouldn't see, it makes much more sense.
I also think, and of course this is just my experience, that you can utilize JQuery without a solid understanding of javascript. Angular and many of these frameworks make so much more sense once you gain a solid footing with the idiosyncrasies of javascript.
You can try to implement Angular's "Hello world" in jQuery. That's where jQuery solution will be more complex, and that's why I like Angular.
I created a gist with another example: https://gist.github.com/denispeplin/5096725
This code I'm using for displaying RRD graphs of different types. I will be surprised if someone will implement same thing in jQuery with same or less amount of JavaScript code.
This is RAILScasts. Playcasts might use the Play Framework and Nodecasts might use Node.js :smile:
I think you are missing the point. Why will you use a framework just to handle clicks? This screen-cast demonstrates ember using a basic app. Anything too complex might get viewers confused. When building a fairly large application, Ember(and others) can come in really handy.
See this post by David Walsh
By using these rich javascript frameworks you only lessen the requirement of ActionView from the rails stack, there is still tremendous use for the rest of the stack. Especially when view rendering is usually a substantial chunk of your entire response times...
Agree with your opinion. I tried to integrate emberjs into my rails app many times, but pitfalls make me question this approch: ember-data is not ready, how to handle error when server validate not pass? Integrate rails authentication, using server render devise view, or make some in ember side? File upload? Twitter switch back to server render... All of these make things difficult. Ember is good, but now I decide stick to plain old rails, because it is sample, I don't have to fight framework. I think future is one framework for client and server. It has enough abstract that app developer only have to think app things.
I have so much difficulty trying to pick which one to learn... ember, angular, or backbone....
I honestly have no idea, and each thing I read about it further makes me indecisive.
If I had to pick one at this moment, I guess I would choose angular. any thoughts?
This is a nice article that explains that: http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/
Read this http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html and use Ember :)
Discourse mentions that Angular's documentation is not that great, which is a fair point. However, ember's documentation helps in the short-term, but does it help in the long-term? And Angular has other documentation apart from its own website, such as Railcast itself.
I am personally still debating on which one to go with. Would you still go with Ember if documentation wasn't an issue?
Just try both on a small app and see which one you like better. Ember may be a bit short on resources to learn at the moment, but I assume that soon this will going to change.
+1
At the risk of being self serving, you can get more info on Ember from http://www.noelrappin.com/mstwjs. Thanks!
Hi Noel i was wondering what is your opinion about Angular, I really want to know your opinion, thank you
Haven't really used it yet. A few people I trust tell me it's pretty good.
Strictly aesthetically, I don't love they way they mix directives into HTML, but I suspect I could get over it.
What I'd like to see is mixing ember with some server side rendering...just to see how I could incorporate this into an existing application.
http://reefpoints.dockyard.com/ember/2013/01/07/building-an-ember-app-with-rails-api-part-1.html
I just did this, pretty good. The promise of Ember, imho, is that everything runs on the client, and the server just becomes a database passing json back and forth for persistance... Ember-data still needs work from what I'm told.
Great Railscast, Ryan (as always).
My co-worker, Tony Coconate, just posted a blog for setting up an Ember.js + Rails API application from scratch. It's a fairly easy process to get this started and he also brings in the use of the Ember Chrome Inspector for debugging:
http://www.devmynd.com/blog/2013-3-rails-ember-js
For those of you daunted by all the multiple files, routing, etc., all just to get a simple app up and running, keep in mind that if you need to put something together for prototyping, or you're having trouble keeping all the different pieces in your brain, here's a simplified JSBin of this Railscast:
http://jsbin.com/ixupad/151/edit
And if you're curious how you could use a HAML/Slim-esque templating alternative instead of Handlebars:
http://jsbin.com/ixupad/152/edit
+1 - when you put it like that, makes it seem very simple...
Is it possible to use Emblemjs in Slim templates?
No, not within a .slim template, but you wouldn't really want to do that anyway. Way better to have it in its own
.emblem
file so you can precompile it and not even have to includeemblem.js
as something your browser has to loadyeah, figured that out! thanks for great work :)
Nice. A direct translation will be http://jsbin.com/ihuqoz/2/edit
It uses an EntriesController.
@Alex, thanks a million for putting this together. It makes it WAY easier to connect the dots between this and traditional JS.
all the frameworks have pros/cons
but heres a pretty nice article on ember
Okay, guys you want a Ember vs Angular opinion - here it is:
Angular is more general and 'address root problem that HTML was not designed for dynamic views' in a very sleek way. It's directives is awesome - if u try it once you just cant forget how beautiful they are!
But he is not ready for a big applications, imho. Just look at his nested routing solution - it doesn't have one! There is only 3rd party module in angular-ui https://github.com/angular-ui/ui-router. No surprise it's version is 0.0.1
Ember is rails-aware and and it's your friend in a middle-size applications.
My opinion that Angular is a competitor rather to Backbone than to Ember. I'll use Angular if to drop interactivity here and there and use Ember for a to have a real front-side application, but... here is the sweet part - Joosy(http://www.joosy.ws/)!
So we have solutions for small, midle, and large front-end applicatoins, isn't this wonderful? :)
Joosy seems does not as easy to use as declared.
This is true for all of them actually: Angular is build by guys with strong technical background and if one will to master it than he should understand wide variety of JS templates: factories, providers, injectors and much more.
Ember is evolving so fast that almost all documentation is out of date :)
Joosy is just one of a kind - but I think Rails world only wins from the diversity it brings into it. Again I haven't work with it because of there wasn't such a demand, but I strongly belives that it have it's layer - large scale rich applications.
If one day content generated by Joosy will be compilant with search engines it will really shine as first-class sitizen in a lots of porjects.
Lots of comments and posts and sample apps.
Is there any sample app or post that implements user login/session?
that's the million dollar question... If you find a good example, let me know...
I would love to see something too...
ember-auth is a gem that's building towards that - looks like they've gone a good way.
Includes a demo project on github, a tutorial, and accompanying working demo site on heroku.
holy crap, that's a awesome tutorial! Just what I was looking for, thanks!
After trying to learn Ember for the past few weeks, starting with the peep code tutorial I can say I'm just starting to "get it." And like everyone on this post I've been reading a TON about ember vs angular. But I haven't actually tried angular. Angular is backed by google! While Ember is two guys in a room, and sure other contributors. But it's the old David and Goliath, and who doesn't want to route for the underdog?
I've also noticed the advanced js programmers tend to use Ember over angular (at least the ones I know), I can only think they have good reason. And from what I can gather it's that you can do more complex things with Ember, at greater speed, once past the learning curve.
Imho Angular and Ember are not in 'versus' position. They both have their use cases.
From my little research of angular I would agree, I can see using it here and there sort of thing. But ember has the potential to change how web apps are built moving forward, the way rails did 10 years ago... At least I think that's the ambition. Will depend in large part on the success or failure of ember-data which is still a work in progress. We shall see.
Exactly! I've faced a problem that ember-data simply don't handle nested resources - there is no way to hit /people/:person_id/something, it will be a /people_something for now.
So, it doesn't matter how mature Ember is, it will be just a local toy until ember-data conforms to its level, imho.
hmmm, interesting.
Also, I've posted some notes on Debugging EmberJS here
Yes, angularjs is great for my contacts app. But ember is better than angularjs for a whole project. Because ember has associations, rails like model, view, router, controller.
USE ANGULAR: If your project has a single model like contact.
USE EMBER: If your project has several models like railcasts.com app.
My 2 cents on Ember after watching this screencast:
- the code after refactoring to extend ArrayController looks actually pretty worse than it was before ( added magic, more lines of code, and bizarre stuff like #each controller ).
- No way in hell am i ever gonna use Ember.js. Weird setters and getters, weird routes that sets controller data, and really a lot of files to do something that looks much simpler in other frameworks. I would prefer going full JS with meteor or another Node framework or Angular.
'#each' feels a lot like ruby. e.g. array.each { |x| puts x }
Pretty sure that's by design. Made me smile when I saw that in ember.
I think it's interesting how emotional people get about frameworks, guess it's a matter of not wanting to waste your time learning something that may or may not be useful in the end. I know I've spent a lot of time learning ember, this better be the next big thing! :)
From my point of view the EmberJs is really powerfully, but apply the EmberJs inside partially client side site is super hard (for me)!
I found really nice alternative the Serenade.js. On home page examples of code with is really easy to understand. I feel that I have control over code, I can understand how it work.
Hope it will help :-)
I am follow this video and get this error
I tried your source, still this error, I am use openSUSE12.3 and installed nodejs, any thing else I miss?
solved by install nodejs from source
Also don't miss the excellent sessions from EmberCamp 2013
I followed instructions to the letter and the request doesn't get routed to the handlebars file it gets routed to index.html.erb. Maybe I'm just tired but this is frustrating. Anyone know why it would route to the application/index file and not application.handlebars?
Check the revision number for the DS.Store. It might need to be updated from 11 to 12
Good article: Ember vs Angular
Great Railscast, Ryan :+1:
Ember.js favors Convention over Configuration which is also a Rails approach.
Here is a good benchmark of Ember, Angular and Backbone: https://www.airpair.com/js/javascript-framework-comparison