Hi All I just finished writing up a tutorial relating my experience developing a system to edit line-items ''in-line'' in my Rails application using XMLHttpRequest. I thought this might be of interest to some readers of this list... Check it out at http://hieraki.goodlad.ca/read/book/1 Thanks! Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
On 07/03/2005, at 10:37 AM, David Goodlad wrote:> I just finished writing up a tutorial relating my experience > developing a system to edit line-items ''in-line'' in my Rails > application using XMLHttpRequest. I thought this might be of interest > to some readers of this list... Check it out at > http://hieraki.goodlad.ca/read/book/1Thanks Dave, great tutorial. There''s a fair few places that I can see could be automated, just like the scaffolding, to create AJAX rails apps much easier (such as the generic JS functions). A few comments: 1) I see that the interface will not work if JS is disabled. It should probably be mentioned that it is possible to write your app such that it also works as normal for people w/o JS (just by using the href="" as you normally would and not doing href="#"). 2) Shouldn''t the JS should be checking whether the xmlhttprequests are actually succeeding or not? 3) Considered using the xmlhttp library from http://www.feedfab.com/xmljs/ ? - tim lucas
On Mon, 7 Mar 2005 12:55:06 +1100, Tim Lucas <t.lucas-l/qNJNvq70OzaBltdDZI6w@public.gmane.org> wrote:> Thanks Dave, great tutorial. > > There''s a fair few places that I can see could be automated, just like > the scaffolding, to create AJAX rails apps much easier (such as the > generic JS functions). >Yep, definitely. Possibly something that could be built into a generator...> A few comments: > > 1) I see that the interface will not work if JS is disabled. It should > probably be mentioned that it is possible to write your app such that > it also works as normal for people w/o JS (just by using the href="" as > you normally would and not doing href="#"). >Ahh, yes, I meant to mention that; Basically this was meant to describe how to make the JS/XMLHttpRequest side work, but not be the be-all-end-all implementation :)> 2) Shouldn''t the JS should be checking whether the xmlhttprequests are > actually succeeding or not? >Yes, they should. They do simple checking of whether or not the server replied with 200, but if it doesn''t it''ll just sit there. As I mentioned in part of the text, checking for the different readystates to display a progress bar, or something like the little notices up in the top-right corner that GMail uses, would work well.> 3) Considered using the xmlhttp library from > http://www.feedfab.com/xmljs/ ? >I did use it originally, but ended up rewriting based on some other code that I saw around the net. It was mostly for my own knowledge, and also because I was having some bizarre errors with POST requests. I thought it may have been related to the way that library was loading things up, but turned out it was a bug fixed in lighttpd the day before :)> - tim lucas > >Thanks for the comments, Tim! Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
On 07/03/2005, at 1:05 PM, David Goodlad wrote:> :snip > >> 2) Shouldn''t the JS should be checking whether the xmlhttprequests are >> actually succeeding or not? >> > > Yes, they should. They do simple checking of whether or not the > server replied with 200, but if it doesn''t it''ll just sit there. As I > mentioned in part of the text, checking for the different readystates > to display a progress bar, or something like the little notices up in > the top-right corner that GMail uses, would work well.Just to bounce an idea: I''m imagining they push save, the form elements disable and you get an (OS X style) animated spinner. If the callback isn''t called after X seconds you renable the form and show an timeout error message (or possibly try making the request again, and on the 2nd timeout you give up and show some type of message). If the response code from the server wasn''t 200 then add the server response above the form and renable the form elements. If the response from the server was 200 and included a <redirect_to> element then redirect the browser to that URL, else leave it up to the JS. - tim lucas
I''ve worked on it little more, to make it simplified. Use it same as in Firefox/Opera i.e.: var xmlhttp = new XMLHttpRequest <code> /** * Cross-browser XMLHttpRequest class. */ if (typeof XMLHttpRequest == ''undefined'') { XMLHttpRequest = function () { var msxmls = [''MSXML3'', ''MSXML2'', ''Microsoft''] for (var i=0; i < msxmls.length; i++) { try { return new ActiveXObject(msxmls[i]+''.XMLHTTP'') } catch (e) { } } throw new Error("No XML component installed!") } } </code> On Sun, 6 Mar 2005 19:05:54 -0700, David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, 7 Mar 2005 12:55:06 +1100, Tim Lucas <t.lucas-l/qNJNvq70OzaBltdDZI6w@public.gmane.org> wrote: > > Thanks Dave, great tutorial. > > > > There''s a fair few places that I can see could be automated, just like > > the scaffolding, to create AJAX rails apps much easier (such as the > > generic JS functions). > > > > Yep, definitely. Possibly something that could be built into a generator... > > > A few comments: > > > > 1) I see that the interface will not work if JS is disabled. It should > > probably be mentioned that it is possible to write your app such that > > it also works as normal for people w/o JS (just by using the href="" as > > you normally would and not doing href="#"). > > > > Ahh, yes, I meant to mention that; Basically this was meant to > describe how to make the JS/XMLHttpRequest side work, but not be the > be-all-end-all implementation :) > > > 2) Shouldn''t the JS should be checking whether the xmlhttprequests are > > actually succeeding or not? > > > > Yes, they should. They do simple checking of whether or not the > server replied with 200, but if it doesn''t it''ll just sit there. As I > mentioned in part of the text, checking for the different readystates > to display a progress bar, or something like the little notices up in > the top-right corner that GMail uses, would work well. > > > 3) Considered using the xmlhttp library from > > http://www.feedfab.com/xmljs/ ? > > > > I did use it originally, but ended up rewriting based on some other > code that I saw around the net. It was mostly for my own knowledge, > and also because I was having some bizarre errors with POST requests. > I thought it may have been related to the way that library was loading > things up, but turned out it was a bug fixed in lighttpd the day > before :) > > > - tim lucas > > > > > > Thanks for the comments, Tim! > > Dave > -- > Dave Goodlad > dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org > http://david.goodlad.ca/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://nohmad.sub-port.net
On Sun, 6 Mar 2005 16:37:44 -0700, David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All > > I just finished writing up a tutorial relating my experience > developing a system to edit line-items ''in-line'' in my Rails > application using XMLHttpRequest. I thought this might be of interest > to some readers of this list... Check it out at > http://hieraki.goodlad.ca/read/book/1 > > Thanks! > DaveJust a quick update; some of you were asking for a live demo and/or source... Check out http://lineitems.goodlad.ca/ for the demo and http://lineitems.goodlad.ca/lineitems.tar.gz for the source. Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
Hi Dave, On Tue, 2005-03-08 at 20:34 -0700, David Goodlad wrote:> Just a quick update; some of you were asking for a live demo and/or > source... Check out http://lineitems.goodlad.ca/ for the demo and > http://lineitems.goodlad.ca/lineitems.tar.gz for the source. >When I go to http://lineitems.goodlad.ca/ I only see the default rails welcome page. What''s the correct url to your app? cheers, mengkuan
On Wed, 09 Mar 2005 11:48:34 +0800, Meng Kuan <mengkuan-i6YX4oj4YlBLCxcys0AdiZqQE7yCjDx5@public.gmane.org> wrote:> Hi Dave, > > On Tue, 2005-03-08 at 20:34 -0700, David Goodlad wrote: > > Just a quick update; some of you were asking for a live demo and/or > > source... Check out http://lineitems.goodlad.ca/ for the demo and > > http://lineitems.goodlad.ca/lineitems.tar.gz for the source. > > > > When I go to http://lineitems.goodlad.ca/ I only see the default rails > welcome page. What''s the correct url to your app? > > cheers, > mengkuan > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Ack, sorry! http://lineitems.goodlad.ca/users/list/ is the right url! Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
On Tue, 8 Mar 2005 21:03:23 -0700, David Goodlad <dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > When I go to http://lineitems.goodlad.ca/ I only see the default rails > > welcome page. What''s the correct url to your app? > > Ack, sorry! http://lineitems.goodlad.ca/users/list/ is the right url!You can fix that by deleting public/index.html and then setting up a route for '''' (eg, the top level URL) to point to whatever you want. -- One Guy With A Camera http://rbpark.ath.cx