egervari
egervari

Reputation: 22512

Is it worth using Rails' built-in Javascript files, or do it from scratch?

For those of you using Rails and a lot of AJAX, what are your thoughts on the built-in functionality for Javascript? What about jquery-rails? Do you go with it? Do you fight against it? Do you start from scratch?

With 3.1 having so many changes when it comes to Javascript, does it make sense to setup your 3.0.7 project in a certain way to make it easier to upgrade later?

Upvotes: 2

Views: 215

Answers (3)

Keith Gaddis
Keith Gaddis

Reputation: 4113

I've formed habits of not touching RJS or any of the Rails JS helpers starting with the 2.x series of releases, mainly because of the obtrusive nature of the Javascript produced. It makes it very difficult to test without resorting to something like Selenium, which I personally regard as a poor substitution for real testability. I don't use them in 3.x either, but the caveat there is that they've been redesigned to be more unobtrusive, though I'm not sure how really unobtrusive RJS could actually become. My recommendation would be to avoid it until you've learned the right way of doing things without them, and then start using them if you find that they provide a real benefit without impeding your development process.

Upvotes: 0

Andy Gaskell
Andy Gaskell

Reputation: 31761

Personally I pass on the Rails helpers. The JavaScript Rails produced used to be obtrusive and wiring up your own ajax in application.js is just so easy with jQuery. That said, in Rails 3 it looks like the helpers are unobtrusive so you should be fine either way. I think no matter what option you choose learning CoffeeScript is a good idea.

Upvotes: 0

apneadiving
apneadiving

Reputation: 115531

Here is my point of view:

  • jquery-rails just make jQuery (+ UI) your Rails' standard js library

  • the only js file made by Rails is rails.js and yes it handles all built-in functionalities and does it really well (example: the delete used in the scaffold generator or the ajax submission of forms)

  • if you are also talking about rjs, this is really a matter of choice. I'd not recommend it for frontend features (cause it's mainly server side), but I like to use it for admin parts.

There are no huge changes concerning js in Rails 3.1, or at least nothing which would make your previous code fail:

  • you still have the choice of your js library

  • you'll be able to use the awesome CoffeeScript as a native part of your dev environment, but it's still not mandatory.

Upvotes: 4

Related Questions