I've been looking at underscore.js and wanted to add it to my rails project. I'm already using jQuery. Is there a best practice when it comes to using these two libraries together? Also, how do you deal with jQuery objects with underscore? Do you use jquery to select a bunch of elements, then run them through underscore?
2 Answers
You can either manually include the underscore js file in your assets, or you can use this gem:
https://github.com/rweng/underscore-rails
Underscore works well with Javascript collections and objects of any kind, so the functions do work well with jQuery objects.
Comments
I suggest you to use it without underscore-rails gem. It is very useless.
It produce nothing but new dependency for the project.
There is no reason to scare using the underscore.js directly.
2 Comments
webjprgm
The gem manages the dependency for you, rather than including underscore.js directly in your repository and having to download a new version when you want updates.
Alexander Popov
@webjprgm That's highly dependent on how often the gem's maintainer does this for you.