| 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: 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 Categories: Tutorial | Ruby On Rails | Forms | Grid | Tree