What’s Coming in Rails 2.0

Things have been pretty fast-paced at RailsConf, so I'm just now getting around to talking about DHH's keynote. After talking a bit about the popularity of Rails since last year's conference in Chicago, he gave a quick run-down of the top 9 new features that will be part of Rails 2.0. Some of this will look pretty familiar if you've been following development on edge:
  1. Breakpoints – After a Ruby bugfix, the breakpointer in Rails stopped working. Rails 2.0 adds this back in with the 'debugger' keyword added to your controller action (previously, you could use 'breakpoint'). Similar to the old breakpoint functionality, the debugger will drop you into an IRb console so that you can inspect local variables. In addition to inspection, you can now traverse the stack, print backtraces, and go back and forth between an IRb session.
  2. HTTP Performance – The performance of a web application suffers as included JavaScript and stylesheets increase in number since they too must be downloaded. Rails solves this problem by modifying the helpers so that these files are compressed for transfer and cached on the client:
     <%= javascript_include_tag :all, :cache => true %> <%= stylesheet_link_tag :all, :cache => true %> 
    Due to the way that browsers operate, they will only make a limited number of connections to a single host when downloading assets referenced on a page. The new use of dynamic asset servers will allow browsers to make more simultaneous downloads from the same host. This is accomplished with a simple configuration change:
    config.action_controller.asset_host = 'assets%d.example.com'
    The sweet spot is cycling between 4 hosts to serve up all your assets; you'll have to add the approprate CNAME records to match the configuration.
  3. Query Cache – Rails is now smart enough to re-use data that it has previously retrieved from the database. When ActiveRecord sees a query for data that it has already loaded, it will hit the cache instead of re-querying the database. Since this happens at the application layer, you don't have to worry about the byte sensitivity of the MySQL query cache. You also don't have to worry about expiring the cache since it gets invalidated each time a change is made to the database (e.g. on insert, update, or delete)
  4. ActionTemplate Renderer – There are new conventions for templates that give greater detail about what each template will render. Views now use the new .erb suffix and indicate their type as part of the template name (e.g. index.html.erb). The same applies with XML files that are created with Builder (e.g. index.rss.builder).
  5. Environment Configuration – As your environment configuration gets complicated, it becomes more useful to break up the configuration into separate files. Rails will now make this easier and allow you to share your more generalized configurations with your other applications.
  6. Sexy Migrations – The migration DSL is getting a facelift and things are getting swapped around. Where we used to have this:
     create_table :users do |t| t.column :first_name, :string, :null => false t.column :last_name, :string, :null => false t.column :account_id, :integer t.column :description, :text t.column :created_at, :datetime t.column :updated_at, :datetime end 

    We now have this:
     create_table :users do |t| t.integer :account_id t.string :first_name, :last_name, :null => false t.text :description t.timestamps end 
  7. HTTP Authentication – While HTTP authentication isn't attractive in HTML-based applications, it's very useful for services that consume data. This works great for authentication-aware applications like feed-readers.
  8. The MIT Assumption – Due to licensing confusion for people using plugins, the new plugin generator now creates a license file by default. The assumption is that you are distributing under the MIT license otherwise you have to modify the file to meet your needs.
  9. Spring Cleaning – In addition to deprecating some features, non-core components like the in-place editing macros have been pulled out into plugins. This is also where you can find useful tools like resource_feeder and open_id_authentication.
If you want to check out some of these features (not everything is out there right now), grab the latest code from SVN or use piston to freeze your application against edge.
Patrick Reagan

Patrick is development director in Viget's Boulder, CO, office. He writes clean Ruby code and automates system infrastructure for clients such as Shure and Volunteers of America.

More articles by Patrick