Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of the script.aculo.us user interface JavaScript library, a member of the Prototype core team and a Ruby on Rails core alumnus. You're using my work every day, even if you're not aware of it (sounds creepy, I know!). Need JS foo? Hire me.

Easier Ajax accessbility with Rails 1.1

March 10th, 2006 by Thomas Fuchs, Comments Off

David writes about the new HTTP accept header handling capability coming in Rails 1.1:


class CommentController < ActionController::Base
  def create
    @comment = Comment.create(params[:comment])

    respond_to do |type|
      type.html { redirect_to :action => "index" }
      type.js
      type.xml  do
        headers["Location"] =
          url_for(:action => "show", :id => @comment.id)
        render(:nothing, :status => "201 Created")
      end
    end
  end
end


This is a sample controller for adding comments to a weblog. It’s able to serve old browsers, Ajaxified browsers, and API access for the blog. Three clients, same controller logic.

Next to allow for totally easy creation of API functionalities in your application, this is also great news for all accessiblilty buffs—easily reusable controller actions for ajax and non-ajax calls are an beta gem away.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Facebook Share on Facebook

Comments Off

JavaScript Rocks! Peformance ebook
Do you run a web site or web application? Do your users a favor, and grab our ebook on JavaScript performance. Profit from our knowledge gathered in over 15 years of working with the Web and JavaScript and make your sites ultra-fast and your users ultra-happy.

Comments are closed.