Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
5 Posts
Javascript

A few things:

  1. Namespace collision is not an issue. Prototype and Mootools would conflict, but you wouldn't be using those on the same page anyway. Prototype and jQuery can coexist in jQuery's special "no conflict" mode (in which jQuery uses a different function name and cedes the "$" to Prototype). But it's just not worth it to use more than one framework — there's nothing functionality-wise that you can get from one but not another.
  2. Rails includes view helpers for visual effects and Ajax stuff. These use Prototype/script.aculo.us out of the box. The "jRails plugin":http://ennerchi.com/projects/jrails changes these helpers to rely on jQuery instead. In addition, RJS is a light enough abstraction that it can work with any framework rather easily.
  3. Script.aculo.us relies on Prototype. You can't use Dojo and script.aculo.us together without also including Prototype — which is possible, but not advisable (see point #1). Dojo has its own effects engine that will do nicely.
  4. The best way to decide which framework to use is to spend a few hours with each one and figure out which makes the most sense in your head.

Disclosure: I am a co-maintainer of Prototype.

I went with jQuery as it did what I needed and I haven't found a place that jQuery didn't work. Honestly not super familiar with all of the other libraries but I say use what you know and what does the job you need.

Really we need someone that does ROR more than I to comment on the libraries and the integration with ROR.

Curtis, thanks for your response. Here's what I got so far, is it correct?

Combining javascript libraries doesn't seem to be a big issue - the main concern is namespace collision.

JQuery and Prototype seem to accomplish the same thing - DOM selection and adding on convenience methods for you to do things to your elements (replace the text within something, hide things, show things, etc). jQuery goes beyond prototype in that it has some visual affects, but they look more limited than scriptaculous (which makes sense as that's all scriptaculous seems to be about, and it comes packaged with prototype). Neither seems to have any widgets, although jQuery seems to have an offshoot library called jQueryUI which has. jQuery actually has a section on their site on how to use it with other libraries and avoid collisions - it looks fairly simple.

scriptaculous seems to be all about visual effects - hiding/showing things in fancy ways, highlighting things for brief periods, sliding things across the screen, etc. They do have some drag and drop features in the library as well, but it doesn't look like they really have any widgets either.

Dojo and YUI seem to combine the same aspects of jQuery or Prototype, as well as providing a widget library (date pickers, dropdowns, grids/tables, etc.) They also both have some animation, although I don't how much there is included in the library. Either could most likely be combined with something like scriptaculous if we wanted access to better animation, if neither has what we want. The animation in either library might be good on their own though.

Another thing to consider is that Prototype and scriptaculous come prepacked with Rails, and as such rails provides convenience methods on using these libraries. One could argue that the HELPERS are more of a crutch though, lots of argument about the helpers - pro and con.

My initial thought: jQuery seems pretty cool as does Dojo. Dojo seems to be better broken out into chunks you can include as you need than jQuery, and seems to have more to offer in most respects if needed. YUI has a lot more widgets than any of the others, but Dojo seems to have more than we'll ever need, jQueryUI seems to have the fewest. YUI performed very poorly in contrast to the other libraries (keeping in mind we're talking milliseconds here, so not a vast difference), and for some reason I just seem to have an version to it from what I've seen. I'm not saying it's logical - but the website and the docs were extremely ugly, which when you're presenting a javascript library says something to me.

After all this; leaning toward Dojo, combined with scriptaculous, if the effects are needed.

What do you think?

Thank-you

I have been talking to some good ROR devs and the answer I get is use what you know. ROR has Prototype and Scriptaculous included but I use jQuery included from the Google code library. I use it cause it's what I know. I believe that jQuery will become more tightly integrated in the future as ROR and MERB become more tightly integrated but honestly I kinda smile and nod when the hard core devs i know talk about MERB.

What are the primary considerations when deciding which javascript libraries to use. Just yanked out twenty hours of Active_scaffold, as its a pain trying to change code and create custom styles. So, we're back to the beginning considering javascript; Prototype, Scriptal, JQuery, Dojo, etc.? Personal choice seems to be most common advise. But would appreciate a more in depth, function/feature based insight.

thanks

5 Posts
Login to add your message