1

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 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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.
@webjprgm That's highly dependent on how often the gem's maintainer does this for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.