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:
- 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.
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.
- 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)
- 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).
- 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.
- 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
- 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.
- 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.
- 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.