stricte / direct-rails

Rails/Merb implementation of Ext.Direct

Home Page:http://www.extonrails.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rails-extjs-direct

THIS GEM IS UNDER DEVELOPMENT AND NOT A FULL IMLPLEMENTATION OF THE Ext.Direct specification

rubyforge.org/projects/rails-extjs/ www.extjs.com

DESCRIPTION:

A series of components for implementing the Ext.Direct API specification in Rails 2.3 and higher. Ext.Direct in Rails is implementede with Rack Middleware.

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({

// Set url corresponding to:  config.middleware.use Rails::ExtJS::Direct::RemotingProvider, "/direct"
url: '/direct',
type: 'remoting',
actions: {
    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:

INSTALL:

sudo gem install rails-extjs-direct

LICENSE:

(The MIT License)

Copyright © 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, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Rails/Merb implementation of Ext.Direct

http://www.extonrails.com

License:MIT License


Languages

Language:Ruby 100.0%