Ext JS - Learning Center

Tutorial:Using Ext with Ruby on Rails Resources

From Learn About the Ext JavaScript Library

Revision as of 09:41, 17 February 2009 by Martinrehfeld-21721 (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Summary: This tutorial gives a general introduction on using Ext JS with Ruby on Rails pointing to further Resources
Author: Martin Rehfeld <martin.rehfeld (at) glnetworks (dot) de>
Published: February 7, 2008
Ext Version: 2.0 +
Languages: en.png English

Intro

How does Ext play along with Ruby on Rails, everybody’s favorite development framework? :-)

There is not a lot of documentation around these days, though some people seem to be using the combo quite successfully. So let's use this tutorial page to gather practical information on the topic.

Ext and Rails in General

The biggest integration task from a Rails point of view is providing the correct JSON data structures that Ext can process. To make life easier, use the Ext Scaffold Generator Plugin. Even if you are not interested in the scaffolding stuff, the plugin will extend the Array and ActiveRecord::Base classes to provide a to_ext_json method. to_ext_json will supply proper JSON for Ext and also format validation error messages attached to ActiveRecord::Base objects. This can be used to provide server-side validations additionally to Ext’s client-side validation features in forms. Additionally, you get a custom MIME type alias :ext_json to be able to handle requests from the Ext frontend separately.

This makes writing controller actions in Rails really easy:

# GET /posts
# GET /posts.ext_json
def index
  respond_to do |format|
    format.html     # index.html.erb (will fire ext_json request)
    format.ext_json { render :json => Post.find(:all).to_ext_json }
  end
end

For a complete example, you can always generate a scaffold for some dummy model and look at the generated code.

Further Resources