5

I intend to program a Bitcoin related Web application with Ruby on Rails. Now there are some very useful libraries out there like Bitcoinjs or Bitcore that are written in Javascript and can be run on the client side in the Webbrowser, or server side with Node.js. However, since I intend to program this application with RoR, I wonder how I can take advantage of those libraries on the server side. Is there a way (i.e. a gem) that allows interpreting Javascript on the server or can I start a Node.js instance in my RoR code by which I can then interpret those javascript libraries and execute their functions? Any help is greatly appreciated.

2
  • I wouldn't recommend it, try and look for native libraries instead of trying to run one in an environment it isn't made for. Doing so usually causes bad performance. Commented Aug 3, 2014 at 23:34
  • Ok, but apart from the performance issue, is it possible and how would it be done? Commented Aug 4, 2014 at 7:03

1 Answer 1

4

Since it seams like you are very determined to use these nodejs libraries, here is how I would go about doing it. Since it is a very bad idea to run code in the wrong environment, I would instead make a setup like this.

Front end, ERB template => Rails server => nodeJs server

The idea behind this setup is that Rails is more like a task master and nodeJs is the worker. Your Rails app would figure out what needs to happen and then tell nodeJs to do it. Nodejs would then respond with the result which Rails would present back to the user.

Here is an example:
Someone on the front end asks you app to transfer x bitcoins to someone else. Your Ruby on Rails app would then do whatever non bitcoin tasks were needed(ex: logging in, messaging people). Then your Rails app would send a request to the nodeJs server which would actually do the bitcoin tasks.

Here is how you would go about implimenting this setup.

  1. Make the front end
  2. Connect frontend actions with your Rails controllers
  3. Make a RESTful HTTP API on your nodeJs.
  4. If you don't already know what a RESTful API is, research it. It is a whole separate topic
  5. Make an entry point for each action you want your app to perform.
  6. Make this nodeJs server run localy, so people can not access it without going through your Rails app
  7. Then use something like restful-client to use you nodeJs API from your Rails app
Sign up to request clarification or add additional context in comments.

2 Comments

Sounds reasonable, yet it seems to be more complicated than I expected. So you are right, probably I am not going to work with these libraries. (Can't vote for your answer due to lack of rep points)
@user3866773 Thats fine. Just accept answer if you think it would help someone with your question in the future.

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.