-
3 Jun 2009 10:37 AM #11
PM me with your email address.
/**
* @author Chris Scott
* @business www.transistorsoft.com
* @rate $120USD / 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 Jun 2009 10:39 AM #12/**
* @author Chris Scott
* @business www.transistorsoft.com
* @rate $120USD / 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 Jun 2009 10:19 AM #13
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
-
28 Jul 2009 4:45 AM #14
I'd be interested in seeing Ext.Direct for Sinatra also
-
25 Aug 2009 4:52 PM #15
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 $120USD / 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
*/
-
25 Aug 2009 5:26 PM #16Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Or, you could monkey patch it

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.PHP Code:(function() {
var originalGetCallData = Ext.direct.RemotingProvider.prototype.getCallData;
Ext.override(Ext.direct.RemotingProvider, {
getCallData: function(t) {
var defaults = originalGetCallData.apply(this, arguments);
return Ext.apply(defaults, {
authenticity_token: '<%= form_authenticity_token %>'
});
}
})
})();
I find this pattern coming up most times I override... perhaps we should have a build in function for it - something like:
Which does the same as my first example, and is powered by:PHP Code:Ext.decorate(Ext.direct.RemotingProvider, 'getCallData', {
authenticity_token: '<%= form_authenticity_token %>'
});
One could probably use Ext's Function methods to do the same job.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(klass, property, config) {
var original = klass.prototype[property];
override = {};
override[property] = function() {
var value = original.apply(this, arguments);
return Ext.apply(value, config);
};
Ext.override(klass, override);
}
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
25 Aug 2009 5:33 PM #17
Very nice!
/**
* @author Chris Scott
* @business www.transistorsoft.com
* @rate $120USD / 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
*/
-
25 Aug 2009 9:08 PM #18
I added some new code-generation features to rails-extjs-direct gem tonight, version 0.0.5
1. Define your direct actions in the controller after including the Mixin:Code:>sudo gem install rails-extjs-direct
2. Get a RemotingProvider instance with new helper method get_extjs_direct_provider. Let your partials add actions to the @provider instance variable.Code:class ExamplesController < ApplicationController include Rails::ExtJS::Direct::Controller direct_actions :foo, :bar . . . end
index.html.erb
3. Adding actions to the @provider instance from within a Partial:Code:<h1>Ext.Direct Remoting Provider Helpers</h1> <% @provider = get_extjs_direct_provider('remoting', '/direct') %> <%= render(:partial => "foo") %> <script> <%= @provider.render %> </script>
_foo.html.erb
5. Rendering the loaded RemotingProvider:Code:<h1>foo partial</h1> <% @provider.add_controller("examples") %>
Will output:Code:<script> <%= @provider.render %> </script>
Note: All Direct-actions are rendered with an argument length of 1.Code:Ext.Direct.addProvider({type: 'remoting', url: '/direct', actions: {"Examples":[{"name":"foo", "len":1},{"name":"bar", "len":1}]}});/**
* @author Chris Scott
* @business www.transistorsoft.com
* @rate $120USD / 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
*/
-
15 Sep 2009 4:27 AM #19
-
22 Sep 2009 7:00 AM #20
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.


Reply With Quote