2

I have started a new project in which I would like to use React and Rails. This project is on the small side and will require some basic interactive UI, hence React. As far as I know there are two ways I could get started with this:

  • Using the react-rails gem and use the built in view helper
  • Create a Rails API and React/Flux frontend app

I have a few questions however. In no particular order:

  • React-rails seems like the simpler solution, but what drawbacks would I be facing?
  • I come from a Rails and Ember background so the Rails API + React FE solution makes architectural sense to me. But with the react-rails gem I'm confused on how some things should be done. Primarily, how do I handle routing? I suppose I won't have access to any react route helpers and will need to pass paths into the react components as props?

Thanks in advance!

1
  • Take a look on this tutorial and this repo (which contains JSX version of code samples from the tutorial). Commented Aug 30, 2016 at 14:49

2 Answers 2

2

For a small project React-Rails, https://github.com/reactjs/react-rails, is great I have used it in production the last year on 2 sites that get about hundred thousand visitors a month and I haven't had any issues.

That said if you want to use Redux, React-Router or Flux don't use React-Rails go the API route.

My rule is if you are just using React components then use React-Rails.

If you are doing a Redux, Flux app then just make a frontend app.

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

Comments

1

It depends on how much your server is doing and also your team. If you have a lot of business logic that you want to keep in Rails, then you may want to have that logic running on a dedicated Rails server and expose as APIs.

You can then have a NodeJS server that does nothing but fetch data from APIs and render React to send to the users. The only interaction between react and rails is via the APIs as JSON. This basic setup will scale really well and is a pretty simple mental model.

If the project gets bigger, this means you can have JS-only devs work in JS only and Rails devs work in Rails only. Plus if you want to move away from Rails or React later, there's no added complexity there.

OR

If all your devs are React+Rails and the project is a bit small for multiple servers, then I think using react-rails to serve up your pages is a fine solution.

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.