0

I need to execute user-entered JavaScript on Heroku under Rails and I want to load underscore.js into my V8 context before running the user-entered js. I'm using the underscore-rails gem for purposes of browser-side execution, so I'd like to pull the underscore.js file from my server gem repository. My question is, how can I "find" this file in the gem repository? Alternatively, is there a better way to handle this?

2 Answers 2

1

Use node.js and then download the npm underscore and then in whichever javascript files you want to use underscore in, at the top put

var _ = require('underscore');

and your in business.

Node can be easily ported to v8, and heroku has everything you need to run it.

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

2 Comments

I appreciate the suggestion, but then wouldn't I be faced with effectively the same problem in terms of where to load node.js and the underscore npm from? I can see benefits to using node's require facility if my needs get more complicated, but if all I need is underscore.js, I don't see what using node and npm buys me.
@PeterAlfvin well it lets you use underscore on the server, and you could then create a v8 interface that allowed you to call it from there. But your right there are definitely simpler ways. One would just be using node to do whatever your trying to do on the server and then just doing something like this to get back to ruby
0

You can find the root of a gem as described in the answer to this question, then just append the relative path to the file you're interested in.

Comments

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.