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?

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106

2 Answers2

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.

Loourr
  • 4,995
  • 10
  • 44
  • 68
  • 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. – Peter Alfvin Jun 24 '13 at 15:13
  • @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](http://stackoverflow.com/questions/8101137/how-can-i-invoke-ruby-from-node-js) to get back to ruby – Loourr Jun 24 '13 at 16:18
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.

Community
  • 1
  • 1
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106