Close and Go BackBack to Viget

What’s Coming in Rails 2.0

Patrick Reagan
Patrick Reagan, Development Director, May 20, 2007 6

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.

Faheem said on 07/19 at 10:23 AM

any idea, when should we expect these features in rail 2.0?

Patrick Reagan - Director, Application Development said on 07/19 at 11:00 AM

@Faheem - I can’t speak for all the planned features, but I’ve already seen most of these on Edge Rails.  If you grab the latest from Subversion and generate the default scaffolding, you’ll see:

<ul>
<li>New template naming conventions</li>
<li>Updated environment configuration (through the <tt>config/initializers</tt> dir)</li>
<li>"Sexy" migrations</li>
<li>MIT license file when generating a plugin</li>
<li>Removal of many core features in favor of plugins (the stock pagination being one of these)</li>
</ul>

I haven’t investigated the other features, but it’s easy enough to get set up with Edge in your own environment to try things out.

Faheem said on 07/23 at 05:07 AM

I get that these features are in edge but I am a little skeptical for using edge in production (I am about to start a web services project exposing a number of stuff to clients and decided for restful rails). Sorry for not being clear in my question the first time, I was just wondering when 2.0 will be out; if you have any idea =)

Patrick Reagan - Director, Application Development said on 07/24 at 09:50 PM

I have no clue when it will officially go “2.0” – I remember when we were all waiting on 1.2 and it seemed like forever.

I have to ask - why the hesitation with using Edge for your project?  At this point, the latest stable version (1.2.3) is over 4 months old, so you’ll be missing out on a lot of cutting-edge features.  Have faith in your test suite and use Piston to maintain your vendor/rails directory.

Trackback: Back From RailsConf Europe » Viget’s Four Labs on 09/22 at 11:11 PM [...] versão 2.0 do framework Rails está por vir e isso significa algumas mudanças e novidades. Já existem vários posts na blogosfera mostrando as particulariedades da nova versão. Vou falar de algumas [...]----- [...] Pilsner!), he announced the upcoming release of Rails 2.0 in the coming months in addition to some new features since 1.2.3. While it was good to finally hear that 2.0 is on the horizon, we’ve actually been ahead of [...]-----
GAry said on 09/30 at 01:16 AM

What about composite primary keys ?

Patrick Reagan - Director, Application Development said on 10/01 at 04:22 PM

@Gary - I haven’t heard any discussion of composite primary keys making it into the Rails core.  If you haven’t already, I suggest you take a look at Dr. Nic’s Composite Primary Keys gem.

We're the Developers

at Viget Labs. We write about web development trends, tips, best practices, industry events, and our projects — all with an emphasis on Ruby on Rails.

Recent Comments

Tony,

I understand and agree that the back-end shouldn’t output code (html code), and only content. The templates (aka views) should do the trick, but instead of having lot’s of if/else conditionals inside the view, you may just output the following content.

No information available

The template would loop in an array and put all the <li>’s inside the <ul>.
I don’t see anything wrong, nor...