RailsConf 2007 - Day 1

Written by on May 19th, 2007 in Ajax News.

RailsConf is underway in Portland, Oregon, and day one (Friday) is in the bad. The keynote by DHH covered what to expect from Rails 2.0. Front and center was an emphasis on RESTful development, which should come as no surprise to anyone who has followed Rails lately. The big takeaway for ajax developers is that Rails will let you return javascript seamlessly for any request, right along side the same code you use for a standard HTTP requests, or XML requests, or whatever. This ultimately means more cohesive, cleaner code in your controllers, and that adding ajax is as easy as adding a format.js to serve XHR requests:

RUBY:

    class PeopleController <ApplicationController
      …
      def create
        @person = Person.create(…)
        respond_to do |format|
          format.html { redirect_to person_url(@person) }
          format.xml  { render :status => :created, :location => person_url(@person), … }
          format.js   {
            render :update do |js|
              … # RJS code here to update the page with js with your created person
            end
          }
        end
      end
    end

Rails 2.0 also has some great optimizations coming for HTTP performance. If you’ve ever looked at the size of prototype+scriptaculous (or dojo, or yui, or…), plus your own custom scripts, PLUS the overhead of the HTTP connections for each seperate javascript file, you know that page load time can get horrendous really quick. The upcoming version will allow easy batching of your js and css, and automatic gzipp’ing when in production, using the standard javascript/stylesheet include tags:

RUBY:

    <%= javascript_include_tag :all, :cache => true %>
    <%= stylesheet_link_tag :all, :cache => true %>

One other quick win Rails 2.0 will give you is multiple hosts for assets. Browsers will only have two concurrent connections open for any single host, but an easy way around that is to use multiple subdomains that resolve to the same domain. So if you set:

RUBY:

    config.action_controller.asset_host = ’static%d.example.com’

Your rails app will randomly choose static01, static02, etc…to get more parallel connections for static assets. This assumes you use the built in img, js, and css helpers, of course.

For more full coverage of the keynote in core-Rails areas, see Nick’s notes.

The other ajax-centered session for the day was on full web stack testing with Selenium Remote Control, by Alex Chaffee and Brian Takita (PDF here). The ajax testing story is still a mixed bag, with a lot of different tools and approaches and not one clear best path. Selenium RC lets you test at the function level of your JS, all the way to a functional level of forms and events, all in the language your app is written in (hence the “remote control” part). For more details see the Selenium link above or the detailed pdf for all the code.

Source: Ajaxian
Original Article: http://ajaxian.com/archives/railsconf-2007-day-1

Leave a Reply

You must be logged in to post a comment.



Site Navigation