1. #11
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default


    PM me with your email address.
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  2. #12
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default


    Quote Originally Posted by somebee View Post
    I have created a merb-router myself, which does not use Parts at all. It exposes all the public controllers and actions automatically (has a helper for generating the direct-api javascript), and maps to the exact same controllers as your public api etc.

    This is done with merb-action-args, so that that I can do this:
    Nice!
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  3. #13
    Ext User
    Join Date
    Jun 2009
    Posts
    5
    Vote Rating
    0
    cbourne is on a distinguished road

      0  

    Default Sinatra

    Sinatra


    Hi this is very intersting.

    Is there any chance of providing a simple Sinatra example of this working?

    Since Sinatra is Rack based and very light it's great for building basic demos/prototypes. Combining it with Ext.Direct would be superb!

    Regards,

    Carl

  4. #14
    Ext User
    Join Date
    Oct 2007
    Posts
    25
    Vote Rating
    0
    Neville Burnell is on a distinguished road

      0  

    Default


    I'd be interested in seeing Ext.Direct for Sinatra also

  5. #15
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default


    If anyone wishes to add Rails' authenticity_token to each request, here's one way to do it:

    Code:
    Ext.override(Ext.direct.RemotingProvider, {
        getCallData: function(t){
            return {
                action: t.action,
                method: t.method,
                data: t.data,
                type: 'rpc',
                tid: t.tid,
                authenticity_token: '<%= form_authenticity_token %>'
            };
        }
    });
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  6. #16
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Quote Originally Posted by christocracy View Post
    If anyone wishes to add Rails' authenticity_token to each request, here's one way to do it:

    Code:
    Ext.override(Ext.direct.RemotingProvider, {
        getCallData: function(t){
            return {
                action: t.action,
                method: t.method,
                data: t.data,
                type: 'rpc',
                tid: t.tid,
                authenticity_token: '<%= form_authenticity_token %>'
            };
        }
    });
    Or, you could monkey patch it

    PHP Code:
    (function() {
      var 
    originalGetCallData Ext.direct.RemotingProvider.prototype.getCallData;
      
      
    Ext.override(Ext.direct.RemotingProvider, {
        
    getCallData: function(t) {
          var 
    defaults originalGetCallData.apply(thisarguments);
          
          return 
    Ext.apply(defaults, {
            
    authenticity_token'<%= form_authenticity_token %>'
          
    });
        }
      })
    })(); 
    The main reason for doing it this way is the override won't break if some important property is added or removed from the returned object in the original getCallData function, we just decorate it instead.

    I find this pattern coming up most times I override... perhaps we should have a build in function for it - something like:

    PHP Code:
    Ext.decorate(Ext.direct.RemotingProvider'getCallData', {
      
    authenticity_token'<%= form_authenticity_token %>'
    }); 
    Which does the same as my first example, and is powered by:

    PHP Code:
    /**
     * @param {Function} klass The constructor function of the class to override (e.g. Ext.direct.RemotingProvider)
     * @param {String} property The name of the property the function to override is tied to on the klass' prototype
     * @param {Object} config An object that is Ext.apply'd to the usual return value of the function before returning
     */
    Ext.decorate = function(klasspropertyconfig) {
      var 
    original klass.prototype[property];
          
    override = {};
      
      
    override[property] = function() {
        var 
    value original.apply(thisarguments);
        
        return 
    Ext.apply(valueconfig);
      };
      
      
    Ext.override(klassoverride);

    One could probably use Ext's Function methods to do the same job.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  7. #17
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default


    Very nice!
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  8. #18
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default


    I added some new code-generation features to rails-extjs-direct gem tonight, version 0.0.5

    Code:
    >sudo gem install rails-extjs-direct
    1. Define your direct actions in the controller after including the Mixin:
    Code:
    class ExamplesController < ApplicationController
      include Rails::ExtJS::Direct::Controller
    
      direct_actions :foo, :bar
      .
      .
      .
    end
    2. Get a RemotingProvider instance with new helper method get_extjs_direct_provider. Let your partials add actions to the @provider instance variable.
    index.html.erb
    Code:
    <h1>Ext.Direct Remoting Provider Helpers</h1>
    
    <% @provider = get_extjs_direct_provider('remoting', '/direct') %>
    
    <%= render(:partial => "foo") %>
    
    <script>
        <%= @provider.render %>
    </script>
    3. Adding actions to the @provider instance from within a Partial:
    _foo.html.erb
    Code:
    <h1>foo partial</h1>
    
    <% @provider.add_controller("examples") %>
    5. Rendering the loaded RemotingProvider:
    Code:
    <script>
        <%= @provider.render %>
    </script>
    Will output:
    Code:
    Ext.Direct.addProvider({type: 'remoting', url: '/direct', actions: {"Examples":[{"name":"foo", "len":1},{"name":"bar", "len":1}]}});
    Note: All Direct-actions are rendered with an argument length of 1.
    /**
    * @author Chris Scott
    * @business www.transistorsoft.com
    * @rate $150USD / hr; training $500USD / day / developer (5 dev min)
    *
    * @SenchaDevs http://senchadevs.com/developers/transistor-software
    * @twitter http://twitter.com/#!/christocracy
    * @github https://github.com/christocracy
    */

  9. #19
    Ext User
    Join Date
    Sep 2007
    Posts
    123
    Vote Rating
    0
    DAddYE is on a distinguished road

      0  

    Default


    Hey,

    why you don't help us to integrate them in LipsiADMIN ?

  10. #20
    Ext User
    Join Date
    Mar 2008
    Posts
    2
    Vote Rating
    0
    kampnerj is on a distinguished road

      0  

    Default Broken in 2.3.3 and 2.3.4?

    Broken in 2.3.3 and 2.3.4?


    rails-extjs-direct seems to be broken on rails releases > 2.3.2

    I get a message about a missing template...


    Processing TestController#destroy (for 127.0.0.1 at 2009-09-22 10:58:27) [POST]
    Parameters: {"tid"=>2, "type"=>"rpc", "data"=>[1]}


    Processing ApplicationController#index (for 127.0.0.1 at 2009-09-22 10:58:27) [POST]
    Parameters: {"id"=>1}

    ActionView::MissingTemplate (Missing template test/destroy.erb in view path app/views):
    /usr/lib/ruby/gems/1.8/gems/rails-extjs-direct-0.0.11/lib/rails-extjs-direct/mixins/action_controller/direct_controller.rb:67:in `rescue_action'
    /usr/lib/ruby/gems/1.8/gems/rails-extjs-direct-0.0.11/lib/rails-extjs-direct/rack/remoting_provider.rb:46:in `call'
    /usr/lib/ruby/gems/1.8/gems/rails-extjs-direct-0.0.11/lib/rails-extjs-direct/rack/remoting_provider.rb:29:in `each'
    /usr/lib/ruby/gems/1.8/gems/rails-extjs-direct-0.0.11/lib/rails-extjs-direct/rack/remoting_provider.rb:29:in `call'

    Rendering rescues/layout (internal_server_error)


    Am I doing something wrong? This works perfectly when I switch the environment back to rails 2.3.2.