Jake Scruggs

writes ruby/wears crazy shirts

Here I am at Rails Conf 2010 in scenic Baltimore, MD and these are my thoughts on the tutorial day.

The Rails 3 Ropes Course - Gregg Pollack and his band of minions (Nathaniel Bibler, Thomas Meeks, Jacob Swanner, Tyler Hunt, Mark Kendall, and Caike Souza)
The worst thing about this presentation is that is was so informative, slick, and well paced that it spoiled me for the afternoon session -- But more on that later. Gregg et al. took on an ambitious task and knocked it out of the park. They discussed a number of new things in Rails 3 and had 5 labs to work through. Every time I was just about done with my lab time was just about up and we moved on. Speaking as a former teacher, that is damn hard to do.

Details:
When setting up a Rails 3 app you can do some interesting things like skip active record, or test unit, or git (What? By default Rails 3 will create an intelligent .gitignore file for you as every Rails developer uses Git (heh)). You can do things like this because of the increased modularity of Rails 3.

The new routes syntax is fun:

  • match 'login' => 'session#new', :as => 'login', :via => :get
  • get '/articles/(:year)' => 'articles#show' # The :year is an optional parameter as it is inside parens.
You can add constrains like so:
:constraints => {:user_agent => /iphone/}

In Rails 3, Bundler is used to manage gems. I've used bundler in a few production apps now and I'm totally in love with it. Bundler does what config.gem was supposed to in an easy and awesome way. And you can use it in 2.3.5! Bundler Rulez! OK, I'll stop now.

ActionMailer now extends from AbstractController.

O.
M.
G.

Now mailers aren't this weird other world that's kinda like a model but kinda like a controller. It uses the same underlying code as the controllers. This is a long needed refractor that has enabled better syntax and less confusion.

ActiveRelation is the new bad-ass relational algebra querying syntax where you can do cool stuff like:
Post.where(:author => "Joe").include(:comments).order(:title).limit(10)

To sum up ActiveModel, all of these things that used to be tightly coupled with ActiveRecord:
  • Callbacks (before and after hooks)
  • Dirty
  • Errors
  • Naming
  • Observing
  • Serialization
  • Translation
  • Validations
Are not anymore and you can use them in ordinal Ruby objects just by including a mixin. Sweet.

Rails 3 assumes any string is an XSS (Cross Site Scripting) attack unless you tell it otherwise and escapes it. To output html in a view, you'll need to use the 'raw' method.

Unobtrusive JS is now used in all the view helpers so if you've ever felt bad about using :confirm => "Are you sure?" but did it anyway because it was just so easy, you can put down that bit of guilt as it all reference a proper Javascript file and with no inline JS.

Rails 3 truly is ponies and rainbows.


Rails 3 Deep Dive - Jeremy McAnally

Tweet from Jeremy McAnally (@jm) 2 days before Rails Conf: "Why wouldn't I catch the flu right before RailsConf where I'm supposed to talk in front of people for a few hours? *sigh* Vitamin-C, engage!"

So the first 10 minutes were about how Rails 3 is basically a Rack app. And then, all of a sudden, we were in a lab. He gave us 3 possible things to build with either Rack or Sinatra. With no explanation of how to do so... So I started to google for Rack docs, but 2 thoughts occurred to me:
1. I could google on my own time.
2. This does not bode well for the rest of the talk.

So I bailed. It could have gotten awesome after that, but the tweets were not kind.

I ended up at:

Contributing to OSS - The 8 Steps for Fixing Other People’s Code - Dr Nic Williams

Which was... Well right after I showed up he had a 'lab' where you were supposed to meet people until you ran into a foreigner. In a way it was valid to have us meet people as open source is all about collaboration. In another, much more real, way it seemed like he was trying to pad a short presentation. He encouraged us to find an open source project an write a 'how to contribute' section for it because almost none of them have one. I then realized that metric_fu doesn't have such a section and wrote one. After that there was some floundering around with git and everyone trying to use the wireless at the same time. I wandered away.

And into an awesome discussion at BOHconf (an open spaces, or 'un-conference' that is running concurrently with Rails Conf at the Baltimore conference center) about fast tests. I got way more out of that half hour than the previous 3 hours combined.

Things I'm planning on looking into:
  • http://grease-your-suite.heroku.com/
  • Turning off your atime and journal data write back for faster file IO (don't try this in prod).
  • Looking at hard disk vs cpu activity during tests.
  • Tweak your test database to delay time to write back and increase its cache size
  • Using Hydra to parallelize your suite -- http://rubygems.org/gems/hydra
  • Specjour - RSpec with bonjour

Things that came up which I hardily recommend:
  • Use Ruby Enterprise Edition and set your GC settings to be absurdly wasteful.
  • Get rid of fat factories (Code that generates a model with lots of models hanging off it -- all of which need to be created in the db).
  • When using Factory Girl (or any other factory that generates ActiveRecord models) just create an instance instead of always saving it to the db. Most times you don't need to touch the database.
Somewhere in there Nick Gauthier declared: "I love making test suites faster. Tell anyone who wants to come by BOHconf and I will make their test suite faster." Take him up on it is my advice.

And then it was time for steak and rum.

3 comments :

paytonrules said...

Minor quibble - Every time I see something in Ruby extend from "AbstractThing" I think - shouldn't that be a module?

Carry on.

Gregg said...

Thanks again for the kind words Jake. We definitely put a lot of work into the Tutorial session, and coming from such a great teacher (that'd be you) it means a lot to hear that you enjoyed it =)

Mr. Neighborly said...

So sorry you felt my talk wasn't on target. I think I presumed way too much knowledge coming in (i.e., that everyone could fairly easily crank out a quick Rack app). Definitely too much presumption on my part. :)

Thanks for coming for the first 10 at least! The second half was probably more your pace. :)