Hello, I''ve just spend weekend playing with orbjson[1] and found it very easy to get working (just a little hacking for charset) and to add it to my rails application, so I wanna ask if there is any other plans for xmlhttprequest in rails or I can go this way and post some ticket on this topic? Sorry, if this was mentioned before, I had three days window for this list, cause full mailbox. I didn''t find anything in archives so .... [1] http://rubyforge.org/projects/orbjson/ http://orbjson.rubyforge.org/tutorial/ getting_started_with_orbjson_short_version.pdf -- Pepe
Josef Pospisil wrote:> Hello, > > I''ve just spend weekend playing with orbjson[1] and found it very easy > to get working (just a little hacking for charset)May I ask what you needed to add, and if it is something I should make a standard part of Orbjson? Thanks, James Britt
Hello, just to add feature to start server with some other charset. I did it by hardcoding it to process_request method of WEBrick_JSON_RPC servlet like this: res[''Content-Type''] = "text/javascript;charset=ISO-8859-2" (I was really looking forward to it working :-). So I hope some litle like argument for server.rb passed to servlets response, will be good. I can even do it by my self, if you want and send you patch (or my apologies if I won''t be able to do it ;-). And I must say it''s really big fun to play with toys like this combined. And last thing is that I guess way for orbjson to rails is clear so my voluntering is not needed. I hoped I should try my first generator :-). Thanks! Pepe On 20.3.2005, at 19:52, James Britt wrote:> Josef Pospisil wrote: >> Hello, >> I''ve just spend weekend playing with orbjson[1] and found it very >> easy to get working (just a little hacking for charset) > > May I ask what you needed to add, and if it is something I should make > a standard part of Orbjson? > > > Thanks, > > > James Britt > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> I''ve just spend weekend playing with orbjson[1] and found it very easy > to get working (just a little hacking for charset) and to add it to my > rails application, so I wanna ask if there is any other plans for > xmlhttprequest in rails or I can go this way and post some ticket on > this topic?There''s already work being done to add XMLHttpRequest features to Rails. From what I hear, it won''t be passing JSON around, but HTML fragments. It''s probably in the SVN repository, I just haven''t gone looking for it. I''m currently using a Ruby-JSON lib (I think http://sourceforge.net/projects/json) for my XMLHttpRequest stuff, so I probably won''t be using it. -- rick http://techno-weenie.net
Rick Olson wrote:>>I''ve just spend weekend playing with orbjson[1] and found it very easy >>to get working (just a little hacking for charset) and to add it to my >>rails application, so I wanna ask if there is any other plans for >>xmlhttprequest in rails or I can go this way and post some ticket on >>this topic? > > > There''s already work being done to add XMLHttpRequest features to > Rails. From what I hear, it won''t be passing JSON around, but HTML > fragments. It''s probably in the SVN repository, I just haven''t gone > looking for it. I''m currently using a Ruby-JSON lib (I think > http://sourceforge.net/projects/json) for my XMLHttpRequest stuff, so > I probably won''t be using it.The Ruby-JSON lib used in Orbjson is the same one on SourceForge, but gem''ed-up on rubyforge so that Orbjson can install it via rubygems. James
Josef Pospisil wrote:> Hello, > > just to add feature to start server with some other charset. I did it by > hardcoding it to process_request method of WEBrick_JSON_RPC servlet like > this: > > res[''Content-Type''] = "text/javascript;charset=ISO-8859-2"Would it be useful to add this as an option to the configuration hash passed to Orbjson::System.init( )? James
I think that it will be the right place. And thanks again for orbjson! That was good weekend spend with it. I still believe (even if rails will have another mechanism to handle xmlhttprequest) that there is place for it in rails for its simplicity. Do you think it could be possible to hook your servlet to rails webrick, because Gecko needs signing scripts from another port or domain. Then just put service classes under app/services, config.yml to config/, javascripts to public/javascripts and so. Some method to ApplicationController like service :name_of_the_service which will add all javascripts to view. I can give some hours on it :-). I''m not really good, but some tests or so ... -- Pepe * When God is with us and for us, just who can be against us?! * Nobody On 20.3.2005, at 22:47, James Britt wrote:> Josef Pospisil wrote: >> Hello, >> just to add feature to start server with some other charset. I did it >> by hardcoding it to process_request method of WEBrick_JSON_RPC >> servlet like this: >> res[''Content-Type''] = "text/javascript;charset=ISO-8859-2" > > Would it be useful to add this as an option to the configuration hash > passed to Orbjson::System.init( )? > > James > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Josef Pospisil wrote:> I think that it will be the right place. > > And thanks again for orbjson! That was good weekend spend with it. I > still believe (even if rails will have another mechanism to handle > xmlhttprequest) that there is place for it in rails for its simplicity. > Do you think it could be possible to hook your servlet to rails webrick, > because Gecko needs signing scripts from another port or domain.Here''s a fairly simple way to use Orbjson with Rails. I did this using WEBrick,I believe it should work with CGI and so on, but haven''t tested it. 1. Create a controller named Services % ruby script/generate controller Services 2. Add this code: # File services_controller.rb class ServicesController < ApplicationController def jsonrpc # Not sure of the Official Rails API for # this. I hacked my own, available upon request. post = get_raw_post_data render_text( ORBJSON.process( post ) ) end end 3. Create a new file in the lib/ dir for the Orbjson class # File hyper-active-orbjson.rb require_gem ''Orbjson'' class HyperActiveOrbjson include Orbjson::Common end 4. Add some stuff to Rails'' config.yml: # Up top, with the other includes, require ''hyper-active-orbjson'' # At the bottom, an Orbjson config string cfg = ''lib/example-service: - Example'' Orbjson::System.init( cfg ) ORBJSON = HyperActiveOrbjson.new 5. Create another file in the lib/ dir, for the example service: # File example-service.rb class Example def times2( x ) x.to_i * 2 end end 6. In some sample HTML page, add some JavaScript to try out this exciting new service. The important part is to get the end-point URL correct, and be sure to copy over the required jsonrpc JavaScript files to your application''s javascripts/ dir: <script type="text/javascript" src="/javascripts/jsonrpc.js"></script> <script language="javascript" type="text/javascript"> var jsonurl = "http://your.rails.app:3000/services/jsonrpc"; var jsonrpc = null; function init() { jsonrpc = new JSONRpcClient( jsonurl ); } function example() { var x = jsonrpc.example.times2( 10 ) alert( x) } </script> Add this for the html body: <body onload=''init()'' onclick=''example()''> 7. Try it out. If all goes well, you should have a controller that uses a reference to a global Orbjson-based class. The controller should get the initial request from the client when you load your test page, and Orbjson should return the list of registered services. The client can then invoke a call to example.times2 when you click on the page. This example uses the Orbjson synchronous client code; it''s simpler to show. All the Rails stuff works the same if you prefer the async JavaScript, but the client code needs some changing. See the example async client code included with Orbjson, or read the tutorial at http://orbjson.rubyforge.org Hope this helps, and comments welcome. James Britt -- http://www.ruby-doc.org http://www.rubyxml.com http://catapult.rubyforge.com http://orbjson.rubyforge.com http://www.jamesbritt.com
I just wake up, and it looks good. I''ll try it after some boring dayjob :-). I used just your tutorial code with running webrick. Javascripts were then comunicating on it''s port which was pain for firefox (hates scripts from other domain or port. Even comunication between them :-). I wasn''t aware of this solution, cause I''m forever nubeeTM :-). I''ll sure have some comments so ... -- Ing. Josef Pospisil On 21.3.2005, at 4:37, James Britt wrote:> This example uses the Orbjson synchronous client code; it''s simpler to > show. All the Rails stuff works the same if you prefer the async > JavaScript, but the client code needs some changing. See the example > async client code included with Orbjson, or read the tutorial at > http://orbjson.rubyforge.org > > > Hope this helps, and comments welcome.
I''ve actually added a Rails wish for this on the wiki: http://wiki.rubyonrails.com/rails/show/IntegrationWithOrbjsonWish On Sun, 20 Mar 2005 23:44:30 +0100, Josef Pospisil <perails-9Vj9tDbzfuSlVyrhU4qvOw@public.gmane.org> wrote:> I think that it will be the right place. > > And thanks again for orbjson! That was good weekend spend with it. I > still believe (even if rails will have another mechanism to handle > xmlhttprequest) that there is place for it in rails for its simplicity. > Do you think it could be possible to hook your servlet to rails > webrick, because Gecko needs signing scripts from another port or > domain. Then just put service classes under app/services, config.yml to > config/, javascripts to public/javascripts and so. Some method to > ApplicationController like service :name_of_the_service which will add > all javascripts to view. > > I can give some hours on it :-). I''m not really good, but some tests or > so ... > > -- > Pepe > > * When God is with us and for us, just who can be against us?! > * Nobody > On 20.3.2005, at 22:47, James Britt wrote: > > > Josef Pospisil wrote: > >> Hello, > >> just to add feature to start server with some other charset. I did it > >> by hardcoding it to process_request method of WEBrick_JSON_RPC > >> servlet like this: > >> res[''Content-Type''] = "text/javascript;charset=ISO-8859-2" > > > > Would it be useful to add this as an option to the configuration hash > > passed to Orbjson::System.init( )? > > > > James > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Here''s a link to my little example using the XMLHttpRequest stuff that''s in Edge Rails: http://www.jroller.com/page/lmarlow/20050317#ajax_on_rails -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Rick Olson Sent: Sunday, March 20, 2005 12:56 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] rails + orbjson> I''ve just spend weekend playing with orbjson[1] and found it very easy > to get working (just a little hacking for charset) and to add it to my > rails application, so I wanna ask if there is any other plans for > xmlhttprequest in rails or I can go this way and post some ticket on > this topic?There''s already work being done to add XMLHttpRequest features to Rails. From what I hear, it won''t be passing JSON around, but HTML fragments. It''s probably in the SVN repository, I just haven''t gone looking for it. I''m currently using a Ruby-JSON lib (I think http://sourceforge.net/projects/json) for my XMLHttpRequest stuff, so I probably won''t be using it. -- rick http://techno-weenie.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Mon, 21 Mar 2005 11:32:15 -0700, Lee Marlow <lmarlow-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Here''s a link to my little example using the XMLHttpRequest stuff that''s in Edge Rails: > http://www.jroller.com/page/lmarlow/20050317#ajax_on_railsVery cool. I had some doubts about the approach, but it looks like it''s done very well. The fact that the remote_function (http://dev.rubyonrails.com/file/trunk/actionpack/lib/action_view/helpers/javascript_helper.rb) helper lets you specify a before/after filter makes me hopeful that I''ll be able to use with JSON being passed around instead of HTML. Looks like now I''ll be holding off on my AJAX development a bit until the next Rails release. -- rick http://techno-weenie.net
On 21.3.2005, at 19:54, Rick Olson wrote:> On Mon, 21 Mar 2005 11:32:15 -0700, Lee Marlow <lmarlow-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> > wrote: >> Here''s a link to my little example using the XMLHttpRequest stuff >> that''s in Edge Rails: >> http://www.jroller.com/page/lmarlow/20050317#ajax_on_rails > > Very cool. I had some doubts about the approach, but it looks like > it''s done very well. The fact that the remote_function > (http://dev.rubyonrails.com/file/trunk/actionpack/lib/action_view/ > helpers/javascript_helper.rb) > helper lets you specify a before/after filter makes me hopeful that > I''ll be able to use with JSON being passed around instead of HTML.I think that there is place for both in framework, too. But there are others for solving this. And even some other things mentioned by Jon in his wish wiki page, looks good to me :-). I will try process described by James, and found what I can do for it. Pepe -- twelfth hour with ruby on rails, and still lovin'' it.