RailsConf 2012: Day One
By Steph Skardal · Monday, April 23, 2012
Today kicks off the official first day of RailsConf 2012, in Austin, Texas (yesterday RailsConf unofficially kicked off with Ignite Rails). This is my fourth RailsConf, and I've found that I get increasingly more out of each one as my time working with Rails has accumulated.
The morning started with a keynote by DHH. DHH talked about progress and keeping an interest in something because it continues to make progress. Initially, the Rails community had a negative reaction to progress like Ruby 1.9, Rails 3, the Asset Pipeline and CoffeeScript, but after the initial learning curve, the new tools and progress was appreciated by the community. DHH talked about how there have been many studies on what prevents people from progressing, and one of those causes is loss aversion, meaning that people hate losing or failing enough that it prevents them from advancing. To me, the point of his talk was to prepare everyone for Rails 4 and how it will challenge and break things. Rails 4 is admittedly not coming out anytime soon, so he didn't touch on any specifics.
Using Backbone.js with Rails
Sarah talked about the love story between JS and Rails:
She touched on the basics of Backbone from a Rails perspective:
- Models: Backbone and Rails models are very similar. An application will likely have Backbone models that mirror Rails models.
- Templates: Backbone templates are akin to Rails views or a mustache template.
- Views: Views are similar to Rails controllers. They set a template, class name, and define events.
Next, Sarah talked about two methods of implementation using Backbone.js and went through some code examples:
- This approach tends to be more API driven and makes sense for an API-driven application that also requires buildout of native mobile apps. - In this approach, the server side returns [JSON, etc.] data and doesn't render HTML. - Sarah noted that the amount of code required here can be substantial because the framework is lightweight, so she would recommended considering alternatives (such as ember.js).
"Backbone as Frosting" Implementation
- In this implementation, there is a mixture of server-side and client-side rendering. - Sarah noted here that the lightweightedness of Backbone works nicely.
CoffeeScript for the Rubyist
Mark then went into a review of Ruby-like CoffeeScript behavior. Below are some of the important topics in CoffeeScript that he covered, as well as links to the documentation:
- conditionals similarity (inline, postfix)
- objects and hashes are similar (can't screw up last comma)
- string interpolation
- heredocs, (""" works)
- functions Ruby 1.9 Lamda syntax is similar to CoffeeScript version
- default arguments
- splats (e.g. first, second, others...)
- loops and comprehensions (for number in numbers)
- combination of loops and comprehensions and conditionals
- inheritence (e.g. class Manager extends Employee)
- Bound functions (with a fat arrow)
- Existential operator (e.g. if foo?, if console?.log "foo")
In addition to the talks on Backbone.js and CoffeeScript, I'll post the links to slides and video for the other talks I attended when they become available.
It's funny (but not surprising) how many of the talks I attended on Day One weren't actually about Rails or the specifics of Rails. Perhaps I'll try to pick a few more Rails-centric talks in the next couple of days of the conference and report on those. Stay tuned!