What is isomorphic Ruby?

Hi, I am a newbie ruby developer, and more often I am starting to hear about this isomorphic ruby, but I don’t fully undesrtand it.

I saw a lot of example with reactJS, when the developer render a component on a server instead that on the client.

I can’t understand why do this? In this way I lose the advantages of the virtualDOM, and the fact that the server just need to send slim response (no template) and the client take care of the rest.

1 Like

Isomorphic Ruby basically means running Ruby code on the backend (the server) as well as on the frontend (the browser).

Traditionally Ruby was used only on the backend, with frameworks such as Rails and Sinatra. Now though, thanks to a brilliant project called Opal, you can write Ruby for the browser - it does this by compiling your Ruby code into Javascript. This means, amongst other things, that you can share code between client and server - resulting in less code/duplication :slight_smile:

The first Isomorphic Ruby framework is called Volt - check it out!

2 Likes

Man I got totally wrong!! Very Very interesting! TY!

1 Like

I have found two cases for needing isomorphic ruby:

  1. Lets say you have a ruby class (or classes) that have complex logic (in our case the job price calculator code.) Currently this code runs on the server with the browser making frequent ajax requests to the server side classes.

Wouldn’t it be nice just to run that code on the browser? Opal makes that no-problemo, BUT we are talking about actual $$ here, so you would like some way to verify the calculations on the server. If you run the code isomorphically, then you can have very fast response on the browser, but be assured that when the user checks out the “cart” the calculations will be safely re-run on the server side in a controlled environment.

  1. Everybody wants to have a nice reactive “single page” style app. But who wants to wait 5 seconds for the server to deliver all the assets, then build the views in the browser, and then have the browser render. So lets run the exact same code on the server, and deliver the pre-rendered view to the browser, FOLLOWED by all the assets that will let the page be fully responsive.

In both cases above, you don’t NEED isomorphic code. You can just duplicate a lot of logic from the server side into the browser.

That’s exactly where my companies website ended up. 8 years ago when we moved to rails ajax was still pretty new, so everything was done server side, but then we started wanting things to be more responsive in the browser so we kept duplicating logic in javascript, until we really have in many places double the logic.

So far we are finding isomorphic ruby really solves the problem, and allows you to think about how you want the SYSTEM to behave to best benefit the user, and not worry about what code has to run where.

1 Like