Om Patel
Om Patel

Reputation: 151

Separating front end from the isomorphic Ruby on Rails web application.

We have our web application built completely on Ruby on Rails. The front end is tightly coupled with the backend. We are in a stage where we want to gradually start separating our frontend from the backend. We want to go ReactJS way with the UI part and we want to follow the waterfall model for the transition.

We have two options:

  1. Use gem called react-rails, and build new components in React. Slowly start converting existing components into React components. Once we have all components converted into React components, take out every React component, separate complete frontend and host it somewhere else.

  2. Host ReactJS somewhere else. Gradually start converting each component to React component, move it to new hosted place and remove them from Rails. The only catch is, React components will be located at a different location than where Rails is. While navigating within the app, it could give a feel of navigating to a different website.

Please share your experience and guide us on which way should we proceed. Our end goal is to have the complete front end in ReactJS and backend on Rails. They communicate via APIs, completely removing coupling between frontend and backend.

Thanks

Upvotes: 1

Views: 1350

Answers (2)

Mitch VanDuyn
Mitch VanDuyn

Reputation: 2878

I would actually NOT recommend going away from your Ruby centered system. You can use http://ruby-hyperloop.io to build your react.js components in Ruby. Hyperloop includes a Ruby DSL (HyperReact) for react, and HyperMesh which will give you complete access to your ActiveRecord models in your React components.

The huge advantages are you will deal with one language throughout, you do not need to build APIs just to access your data down at the client, and you can use the existing rails tool chain including test tools.

There is a huge library of React.js components which interoperate fine with HyperReact.

If for whatever reason you feel that it would be better to go the JS route then I would recommend react-rails. It works, is well supported, and handles prerendering (a very important concept.) You can easily integrate with NPM and webpack as well.

Upvotes: 1

zanedev
zanedev

Reputation: 568

Use #1 only if you plan on keeping rails in the server rendering mix (not recommended). If not then #2 is your best option to just start from scratch with a complete js solution. It doesn't have to feel like a different site if you create a decoupled react component library and a rendering pipeline to the existing rails app when it needs the new views. Then when you have converted all the view components you can wrap up the app logic and make the switch over entirely.

Another option is you don't even need to host the new react components seperately, the react components can go through a separate build cycle, then cached on the existing server and rendered as needed from rails.

Upvotes: 1

Related Questions