The Artima Developer Community
Sponsored Link

Ruby Community News Forum
Ruby on Rails 2.0 Preview Released

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Ruby on Rails 2.0 Preview Released Posted: Oct 2, 2007 12:57 PM
Reply to this message Reply
Summary
The Ruby on Rails project released a preview of the upcoming Rails 2.0 framework. Notable improvements include even more REST-friendly APIs, easier security configuration via HTTP authentication, more abstraction in templating, including support for the iPhone, and performance improvements.
Advertisement

The Rails project released a preview of Rails 2.0, the upcoming version of the popular Ruby Web framework. In an overview blog post, Rails instigator David Heinemeier Hansson provides an overview of notable new features.

Among the more interesting features is an even closer affinity with RESTful services:

We’ve got a slew of improvements to the RESTful lifestyle. First, we’ve dropped the semicolon for custom methods instead of the regular slash. So /people/1;edit is now /people/1/edit. We’ve also added the namespace feature to routing resources that makes it really easy to confine things like admin interfaces:

map.namespace(:admin) do |admin|
  admin.resources :products,
    :collection => { :inventory => :get },
    :member     => { :duplicate => :post },
    :has_many   => [ :tags, :images, :variants ]
end

Which will give you named routes like inventory_admin_products_url and admin_product_tags_url. To keep track of this named routes proliferation, we’ve added the “rake routes” task, which will list all the named routes created by routes.rb.

Rails 2.0 also provides improvements in integration with template engines by allowing to specify what engine a response should be rendered by:

We’ve separated the format of the template from its rendering engine. So show.rhtml now becomes show.html.erb, which is the template that’ll be rendered by default for a show action that has declared format.html in its respond_to. And you can now have something like show.csv.erb, which targets text/csv, but also uses the default ERB renderer...

show.erb: same show template for all formats
index.atom.builder: uses the Builder format, previously known as rxml, to render an index action for the application/atom+xml mime type
edit.iphone.haml: uses the custom HAML template engine (not included by default) to render an edit action for the custom Mime::IPHONE format

Speaking of the iPhone, we’ve made it easier to declare “fake” types that are only used for internal routing. Like when you want a special HTML interface just for an iPhone.

It is also possible to serialize and de-serialize to and from XML and JSON and Ruby classes:

In 2.0 we’ve added deserialization too, so you can say Person.new.from_xml(“David“) and get what you’d expect. We’ve also added serialization to JSON, which supports the same syntax as XML serialization (including nested associations). Just do person.to_json and you’re ready to roll.

A new Rails 2.0 module supports HTTP Basic authentication:

We’ve added a new module to work with HTTP Basic Authentication, which turns out to be a great way to do API authentication over SSL. It’s terribly simple to use. Here’s an example (there are more in ActionController::HttpAuthentication):

  class PostsController < ApplicationController
    USER_NAME, PASSWORD = "dhh", "secret" 

    before_filter :authenticate, :except => [ :index ]

    def index
      render :text => "Everyone can see me!" 
    end

    def edit
      render :text => "I'm only accessible if you know the password" 
    end

    private
      def authenticate
        authenticate_or_request_with_http_basic do |user_name, password| 
          user_name == USER_NAME && password == PASSWORD
        end
      end
  end

Rails 2.0 also includes numerous performance improvements, including query caching:

Something new that we have added, though, is a very simple Query Cache, which will recognize similar SQL calls from within the same request and return the cached result. This is especially nice for N+1 situations that might be hard to handle with :include or other mechanisms.

What do you think of the new Rails 2.0 features?

Topic: Roman Strobl on NetBeans' Ruby Support Previous Topic   Next Topic Topic: Threading in the New Ruby VM

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use