September 18, 2007

RailsConf: The DHH keynote - Rails 2.0 update

Filed under: rails, railsconf — Casper Fabricius @ 5:35 pm

This article summarizes some important points from David Heinemeier Hansson’s keynote at RailsConf Europe 2007 in Berlin. Last year, DHH brought us the whole REST way of thinking which I immediately named normalization, but that term didn’t really catch on.

David Heinemeier Hansson
© 2007 Pinar Ozger

This year, DHH noted that he up until now had started all his previous keynotes about Rails celebrating how “freakin’ fantastic we are”. For this keynote, he thought - with Rails being well within in its third year in existence - that it was time to perhaps be happy with what we have.

He explained that new things tend to go through certain phases: First they ignore you, then they laugh at you, then they fight you, and then you win - … and then what? “Ruby on Rails went through these phases way too fast”, DHH said, “I was having a lot of fun going through these phases; I’m kind of sad it is over.”

For the last couple of years, David and the Rails community has pushing new concepts; Convention over configuration, AJAX and REST, but these focal points were adopted very fast, so there is no big cause to fight for right now. That leaves Rails 2.0 in a really weird spot, since it won’t have any groundbreaking new concepts.

This is not a bad thing, though, DHH stressed. “Even though [the lack of a great cause] is an off-switch for me, it’s not about me anymore”, he said. “Rails are moving from big revolutions to tiny evolutions” - a statement that was underlined when David went on to demonstrate new features in Rails; features that were definitely more tiny evolutions than big revolutions.

But before we get to the Rails 2.0 code examples of the keynote, let me just mention something that was news to me: The new policy for how to get a patch into Rails, also known as Report #12. The idea is basically that you, once you have written a patch and submitted it to the Rails trac, should get three other Rails developers to check out your patch, verify that your tests run, and then add a “+1″ in a comment in trac. Once you have your three “+1″’s, you tag your patch with the keyword “verified”, and the patch will appear in Report #12: Verified Patches. The core team should then - theoretically - be able to very fast to accept the patch into Rails.

Moving on to the, in my opinion, most interesting part of the presentation: What’s new in Rails 2.0 - show me the code! Migrations has been updated to support a new syntax known as “sexy migrations”, which basically allows even shorter and more readable migrations by grouping fields of the same type:

create_table :blogs do |t|
	t.string :title, :subtitle
	t.text :body, :description
	t.integer :category_id
	t.timestamps # Adds created_at and updated_at fields
end

Notice how another evolutionary improvement has been sneaked in: Tired of always adding created_at and updated_at timestamps to most tables, a timestamps method has been added as a shortcut. Also this new syntax, including the timestamps, is now standard in the model and scaffold generators.

A small, but to me significant improvement has also found its way to Rails 2.0: You can now create the needed databases with a rake command. By running this command, all referenced databases in your database.yml will be created:

rake db:create:all

Another interesting, and perhaps generally quite invisible improvement, is that session data are now stored in a encrypted cookie instead on each server, which makes it easy to partition applications across multiple servers without having to put session data in the database. This requires, of course, the session data to be quite compact (storing id’s, not entire objects), as a cookie can contain 4 KB of data the most.

My favourite point of DHH’s keynote was his solution to the common pattern of a resource, which you both need to display to the common user (usually index and show) and to the admin user (usually index, new, create, edit, update and destroy). The normal RESTful solution to this leaves with a problem, because we are only allowed one index action, and we need two; one for the common user and one for the admin user. Also, the admin actions will usually have a different layout than the common user actions, and they require some kind of authorization.

The solution is to used RESTful namespaced routes, referring to two different controllers with the same name, but in different namespaces. To use DHH’s eternal blog example:

./script/generate controller posts # => /controllers/posts_controller.rb
./script/generate controller admin::posts # => /controllers/admin/posts_controller.rb

Now we have two different controllers working in the same model; Post, but offering different actions, layouts, authorization and so on. This nice thing about this solution, is that it is very easy to understand and fits well into the Rails structure. The catch is that we have two controllers with the same name, so we need to explicitly express the namespace when referring to the admin controller:

form_for([:admin, post]) do |f|
	...
end

DHH also pointed out that HTTP authentication is a perfect way of doing authentication for administration pages (which I’d already realized). You don’t really need nice-looking form-authentication and remember me checkboxes for that, and it is so very easy to implement with Rails 2.0:

# In a controller or module shared between admin controllers
before_filter :ensure_administrator
def ensure_administrator
	authenticate_or_request_with_http_basic('Blog admin') do |username, password|
		username == 'dhh' && password == '123'
	end
end

A very visible change in Rails 2.0 is the naming of views. The .rhtml, .rxml etc. file endings has been discarded to replaced by the form [name].[mime-type].[renderer]. This leaves the road open for file names such as:

  • index.html.erb
  • index.xml.builder
  • index.html.liquid
  • index.iphone.erb

The last example needs a little additional configuration, since iphone is not a “real” mime-type, but we can easily make Rails treat it like such:

# In mime_types.rb:
Mime::Type.register "application/x-iphone"

# In application.rb:
before_filter :adjust_format_for_iphone
def adjust_format_for_iphone
	if request.env["HTTP_USER:AGENT"] ~= /iPhone/
		request.format = :iphone
	end
end

# In specific controllers
respond_to do |format|
	...
	format.iphone do
		render :text => 'Hello iPhone', :content_type => Mime::Html
	end
end

Notice how content_type must manually be set to Mime::Html, as the iPhone browser - as well as any other browser - doesn’t recognize our fake x-iphone mime-type, and Rails will always default to respond with the request mime-type.

My second favourite point was about the “new” debugging support in Rails 2.0. As I understood it, the well-known ruby-debugger library has been baked into Rails 2.0, so that we write debugger instead of breakpoint, and need to start the server with a --debugger prefix (./script/server --debugger) to enable these breakpoints. This debugger also support more advanced commands such as “cont” (continue), “list” (view current code) and “up” (step out).

David Heinemeier Hansson rounded off his keynote by announcing the release of a Rails 2.0 Preview Release (how Microsoft-ish does that sound?) either during or shortly after the conference.

You can download my full notes from the keynote here.

UPDATE: My other notes from RailsConf Europe 2007 are now available.

32 Comments

  1. DHH’s Keynote at RailsConf Europe…

    Some notes from David Heinemeier Hansson’s keynote by Casper Fabricius…….

    Trackback by Stefan Tilkov's Random Stuff — September 18, 2007 @ 8:29 pm

  2. […] Currently keynoting RailsConf Europe in Berlin (Notes from his keynote). […]

    Pingback by Screen Snooze » Blog Archive » Upcoming 37signals Speaking Engagements — September 19, 2007 @ 12:04 am

  3. Upcoming 37signals Speaking Engagements…

    David

    Currently keynoting RailsConf Europe in Berlin (Notes from his keynote).

    Jason

    Keynoting […]…

    Trackback by Minefeed.com — September 19, 2007 @ 12:40 am

  4. […] That’s kind of cool, I was reading a post about DHH Keynote at RailsConf Europe when I realized that DHH mentioned one of my contribution to Rails Edge. […]

    Pingback by GSIY … Ruby-Rails Portal — September 19, 2007 @ 6:28 am

  5. Nice summary. Do you know of others that are documenting the conference on their blogs?

    Comment by Obie — September 19, 2007 @ 3:49 pm

  6. […] Casper Fabricius wrote a nice summary of the keynote. […]

    Pingback by DHH keynote @ European Railsconf 2007 « Pardel’s Blog — September 19, 2007 @ 6:29 pm

  7. Looks pretty sweet! The namespaces idea seems similar to sections in Monorail. Unless Rails already had this and I’m just ignorant (still a beginner).

    -Joe

    Comment by Joe — September 19, 2007 @ 6:36 pm

  8. Obie, thanks, and nice to hear from you again. Atlantic Dominion Solutions seem to have some pretty comprehensive summaries, and the guy at Liverail seem to have been all the sessions I missed, so I’m definitely going to have a look at that too. By the way, Presentation slides are online.

    Joe, you are right, the concepts seem similar. Nested routes are not new in Rails as such, but I think it’s new that we call them namespaces, and I think they are much better supported and integrated in Rails 2.0. I asked David explicitly about this, and he explained that you need to define the scope for all references to namespaced actions.

    Comment by Casper Fabricius — September 19, 2007 @ 9:57 pm

  9. The photograph of DHH above is by Pinar Ozger. Linking back to the Flickr page is appreciated, but you should also always give textual attribution for images that you source, even when used in a non-commercial fair-use way like this on a personal blog. It’s kinda like when you attribute a quote or a passage of text to somebody. Thanks.

    Comment by Pinar Ozger — September 19, 2007 @ 10:23 pm

  10. Caspar, great write-up as usal. One of these days I’ll try to make it out to RailsConf Europe and we can meet up again.

    Comment by Jeff — September 20, 2007 @ 12:35 am

  11. Casper, controller namespaces are not nested routes, and have been around (in various states of working-ness) since before 1.0. It’s great to see them getting some love, though.

    Comment by twifkak — September 20, 2007 @ 5:53 am

  12. Pinar; fair enough. Other photographers seems to be content with a back-link to Flickr, though, which is why I haven’t thought of it.

    Jeff; thanks, and yes - please do! :)

    twifkak; thank you for pointing that out, I stand corrected.

    Comment by Casper Fabricius — September 20, 2007 @ 2:35 pm

  13. […] RailsConf: The DHH keynote - Rails 2.0 update. […]

    Pingback by Morning Brew #77 — September 20, 2007 @ 4:32 pm

  14. […] P.S.: My keynote slides were few and almost entirely without meaning out of context, but Casper Fabricius did a good job with his summary. Blogs, RubyOnRails Home | | Login|Feed © 2007 GSIY … Ruby-Rails Portal | GooMedic.com | Neoxero.com […]

    Pingback by GSIY … Ruby-Rails Portal — September 20, 2007 @ 10:21 pm

  15. Thanks - I am greatly excited about rails 2.0. I am still getting to grips with rails in general but the improvements / refinements talked about are so neat.

    Rails Rocks!!

    Comment by Jontyjont — September 21, 2007 @ 12:25 am

  16. […] RailsConf Europe 2007 is over and it’s time to wrap up. As before, there are oodles of pictures on Flickr with the “RailsConfEurope” tag (yah-boo to you miserable sods who don’t use Creative Commons licenses for your photos) and DHH points to all of the presentations given at the conference (covering areas as wide as Ferret, REST, Adobe Flex, Amazon S3 and JRuby). Continuing from his fine coverage of Monday, the first day of the conference, Robert Dempsey succinctly wraps up the Tuesday morning and afternoon sessions, as well as the Wednesday morning sessions, and then Wednesday in its entirety. These are worth a read if you didn’t go, as he provides some context missing elsewhere. Last but not least, David Heinemeier Hansson’s keynote. The King of Rails seemed to focus mostly on Rails 2.0, which will be more of an evolutionary step than a revolutionary one. Casper Fabricus has a superb writeup with many choice quotes and code examples, although Nick Sieger has done a good job too. On his own blog, however, the King decided to post his views of Sun’s ever-growing support for Ruby and Rails and his ultimate satisfaction at the success of RailsConf in general. […]

    Pingback by RailsConf EU 2007 Wrap Up — September 21, 2007 @ 1:41 am

  17. […] So I’ve been reading about the interesting talks at Railsconf Europe. The slides for all of the presentations are here.  And a Google Blog search will turn up a lot of opinion and summaries of the various presentations. The most interesting summary I found was this one of DHH’s keynote address. […]

    Pingback by codevader » Blog Archive » Railsconf Europe — September 21, 2007 @ 8:09 am

  18. form_for([:admin, post]) do |f|

    gah!! I’ve been doing this exact setup (admin namespace) for months (edge) and have been having to hand-solve the form_for problem - and there it was the whole time.

    Comment by tadly — September 21, 2007 @ 8:46 am

  19. […] Thanks to Casper Fabricus for a great summary of David’s keynote. […]

    Pingback by Mike Bailey - Freelance Web Application Programmer — September 21, 2007 @ 11:21 am

  20. Thanks Casper. I appreciate you updating the page. The Internet has been a free for all for images for a while, and Copyright law is certainly in need of changes, but the idea of Fair Use is a powerful one and providing credit can only help encourage others to pursue photography and provide images.

    Comment by Pinar Ozger — September 21, 2007 @ 11:41 am

  21. Thanks for the update on RailsConf Berlin, Casper (sounds like it was fun). I was confused to hear about the talk on namespaced controllers; people have always been using namespaced controllers. It happens less now with RESTful Rails, but it seems like it’s always been an option (the ‘admin’ problem being the most common use of it). Is the only thing that’s new about this that there’s support for it in form_for()?

    Comment by Tieg — September 21, 2007 @ 6:04 pm

  22. […] Angefangen mit der Keynote von DHH wurde relativ schnell klar, dass Rails sehr bald in eine neue Richtung geht bzw. in eine neue Phase eingetreten ist. Rails ist in der kommerziellen Welt angekommen. Es gibt (erstmal) keine “großen Revolutionen” mehr, sondern es ist nun Zeit die Benefits von Rails zu geniessen und anzuwenden. Rails 2.0 steht vor der Tür und wird sehr bald in einem Preview Release verfügbar sein. Darin wurde aufgeräumt, ausgelagert, an Details verbessert und weniger gute Konzepte über Bord geworfen. […]

    Pingback by Meine Eindrücke von der Railsconf Europe 2007 in Berlin  -  Oliver Kießler’s Weblog — September 22, 2007 @ 9:41 pm

  23. […] RailsConf Europe 2007 is over and it’s time to wrap up. As before, there are oodles of pictures on Flickr with the “RailsConfEurope” tag (yah-boo to you miserable sods who don’t use Creative Commons licenses for your photos) and DHH points to all of the presentations given at the conference (covering areas as wide as Ferret, REST, Adobe Flex, Amazon S3 and JRuby). Continuing from his fine coverage of Monday, the first day of the conference, Robert Dempsey succinctly wraps up the Tuesday morning and afternoon sessions, as well as the Wednesday morning sessions, and then Wednesday in its entirety. These are worth a read if you didn’t go, as he provides some context missing elsewhere. Last but not least, David Heinemeier Hansson’s keynote. The King of Rails seemed to focus mostly on Rails 2.0, which will be more of an evolutionary step than a revolutionary one. Casper Fabricus has a superb writeup with many choice quotes and code examples, although Nick Sieger has done a good job too. On his own blog, however, the King decided to post his views of Sun’s ever-growing support for Ruby and Rails and his ultimate satisfaction at the success of RailsConf in general. […]

    Pingback by GSIY … Ruby-Rails Portal — September 22, 2007 @ 11:39 pm

  24. Tieg; as much as I’d like to be able to answer to you, the truth is I haven’t been playing much with edge myself lately, so I don’t know - maybe I’ve mixed up two completely different things in my article?

    Comment by Casper Fabricius — September 23, 2007 @ 6:31 pm

  25. I wondered the same thing as Tieg. Also, I thought namespaced controllers were actually being frowned upon as not very DRY once the whole RESTful controller movement started up. Maybe I’m remembering my rails history wrong…

    Comment by Justin — September 24, 2007 @ 4:14 pm

  26. Yeah.. grouping controllers using namespaces is already exists in 1.2 (along with support to pass namespace to script/generate command)

    Comment by Bob Lakkakula — September 25, 2007 @ 6:17 am

  27. […] http://casperfabricius.com/blog/2007/09/18/railsconf2007-dhh/ […]

    Pingback by Null is Love » Blog Archive » RailsConf Europe — September 26, 2007 @ 8:00 pm

  28. […] Since I am going to purchase an iPod touch, thought I’d start looking into building apps for the iPhone. I love the Rails support. […]

    Pingback by Random Syntax » iPod Touch - gotta get one — September 27, 2007 @ 2:20 pm

  29. […] Further details from DHH’s talk have been blogged in detail. Personally, I’m really looking forward to the release of Rails 2.0; evolution rather than revolution. […]

    Pingback by GSIY … Ruby-Rails Portal — October 2, 2007 @ 10:38 am

  30. […] The changes to the Routing system have received plenty of attention elsewhere, but I wanted to pull out one tidbit which I’ve only seen posted one other place, Casper Fabricius’ excellent recap of DHH’s keynote address at Railsconf Europe: […]

    Pingback by GSIY … Ruby-Rails Portal — October 3, 2007 @ 8:31 pm

  31. […] DHH előadása összefoglalva Dave Thomas - The art in rails Jegyzetek az előadásokról, txt-ben […]

    Pingback by Még egy kis Rails Conf 2007 : Pixelszabászat — October 5, 2007 @ 11:13 am

  32. very interesting, but I don’t agree with you
    Idetrorce

    Comment by Idetrorce — December 15, 2007 @ 1:44 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.