views:

234

answers:

3

I'm working on my first Ruby on Rails aplication and it's quite big (at least for me ;) - database has about 25 tables). I'm still learning Ruby and Rails and I never wrote anything in Javascript nor Ajax. Should I add Ajax to my application from the begining? Or maybe it will be better to add it latter?

Or in the other words: is it (relatively) easy to add ajax to existing web application?

+1  A: 

If you are planning to do AJAX, I would do it from the beginning. It will help you structure your controller actions and views, especially with respect to generating some data in partial views, correctly from the very beginning. Knowing that some actions need to be able to render just parts of the page will change your design. This isn't to say that you can't go back and retrofit the design, but I think it's easier to get the design right if you design with this in mind up-front. You should also consider how to make it work without AJAX (or javascript at all), too so that your design is as fail-safe as possible. That doesn't mean that all functionality has to be available, but that important functionality works in the absence of javascript. For example, action links that use AJAX should have a default url that will invoke the correct action via a GET request if the javascript isn't enabled. Forms that post via AJAX should also work if posted normally. Dynamic behavior (like an image gallery) should have a usable, alternative view that works, etc.

tvanfosson
+10  A: 

Jeremy Keith has written a great article on this topic, which he refers to as Hijax

In short:

  • Plan for Ajax from the start.
  • Implement Ajax at the end.
Mark Hurd
In my experience sometimes stuff that "gets done at the end" never gets done. Also, planning without delivering doesn't really work. You don't get any feedback on the design until it's too late.
tvanfosson
usually people say build the site first, add js later. that gets you into some trouble and this method is meant to fix those troubles
LDomagala
+4  A: 

Depends on how important Ajax is for the application. Since you are probably going to use Ajax for progressive usability enhancements only, I would say it is best to start with a traditional non-Ajax software, and add Ajax features only when you have the first features working. You can do this feature by feature, or write the whole software first, and then start ajaxing it.

Adding Ajax may be easier if you familiarize yourself with unobtrusive JavaScript techniques. Use jQuery instead of Prototype.js, or LowPro in addition to Prototype.js. For the latter, see e.g. Jarkko Laine's PDF book Unobtrusive Prototype.js.

Antti Tarvainen