README.rdoc in rails-extjs-direct-0.0.2 vs README.rdoc in rails-extjs-direct-0.0.3
- old
+ new
@@ -1,7 +1,7 @@
= rails-extjs-direct
-THIS GEM IS UNDER DEVELOPMENT AND WILL NOT YET WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+THIS GEM IS UNDER DEVELOPMENT AND NOT A FULL IMLPLEMENTATION OF THE Ext.Direct specification
http://rubyforge.org/projects/rails-extjs/
http://www.extjs.com
== DESCRIPTION:
@@ -11,50 +11,78 @@
== FEATURES/PROBLEMS:
== SYNOPSIS:
+* STEP1: Attach Rack MiddleWare to Rails config in environment.rb. The "/direct" bit is the url
+designated as Ext.Direct request.
+
+require 'rails-extjs-direct'
+Rails::Initializer.run do |config|
+ config.middleware.use Rails::ExtJS::Direct::RemotingProvider, "/direct"
+ .
+ .
+ .
+end
+
+* STEP2: Include Rails::ExtJS::Direct::Controller mixin into each controller you wish to be "Directable":
+
+class CompanyController < ApplicationController
+ include Rails::ExtJS::Direct::Controller
+
+ def destroy
+ # The Direct::Controller mixin will provide an instance variable @xrequest to each action.
+ # @xrequest is an instance of class XRequest provided by the rails-extjs-direct gem.
+ # XRequest contains accessor methods for each parameter in the Ajax request, including "tid", "type",
+ # "data", and "id"
+ #
+ # You must always render an instance of XResponse. Use the @request instance when instantiating
+ # your XResponse. This will ensure that Ext.Direct receives the correct "tid" (transaction id).
+ #
+ res = XResponse.new(@xrequest)
+ res.status = true
+ res.message = "Company#destroy"
+ res.result = {:foo => 'bar'}
+ render(:json => res)
+ end
+end
+
+* STEP 3 -- Define your Ext.Direct client-API
+
<script>
Ext.Direct.addProvider({
- url: '/admin/rpc', //<-- Note the url corresponding to Admin above.
+ // Set url corresponding to: config.middleware.use Rails::ExtJS::Direct::RemotingProvider, "/direct"
+ url: '/direct',
type: 'remoting',
actions: {
- Users : [
+ Company : [
{name: 'load', len: 1},
{name: 'save', len: 2},
{name: 'create', len: 1},
{name: 'destroy', len: 1}
]
}
});
+
+// The following series of actions will generate just 1 Ajax request.
+Company.create({name: "Slate International"});
+Company.destroy(1, function(result, response) { console.info(arguments);});
+Company.destroy(2);
+Company.destroy(3);
+
</script>
== REQUIREMENTS:
-merb-parts
-
== INSTALL:
-sudo gem install merb-extjs-parts
+sudo gem install rails-extjs-direct
-IMPORTANT: This gem includes a required javascript file named "merb-extjs-direct.js" in the root of this gem.
-Currently you MUST copy this file to your /public/javascripts directory and included it immediately the ext
-framework's assets (ie: immediately after "ext-all.js").
-
-merb-extjs-direct.js contains a couple of simple overrides of the Ext.Direct library which will rename two
-HTTP request parameters to be more Merb/Rails-like. By default, Ext.Direct uses the word "action" where Merb
-uses "controller" and "method" vs "action". Confusing, eh? The HTTP params are actually renamed xcontroller
-and xaction to not interfere with Merb reserved words. If you don't see "xcontroller" / "xaction" params
-in your Ajax requests, make sure you've got merb-ext-direct.js included.
-
-In the future, I'll have >rake install automaticlly copy this file to /public/javascripts (Would anyone like to
-contribute some code to do that?)
-
== LICENSE:
(The MIT License)
-Copyright (c) 2009 FIX
+Copyright (c) 2009 Chris Scott
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,