ROR + React

620 views
Skip to first unread message

Joe Guerra

unread,
Aug 19, 2019, 2:48:03 PM8/19/19
to Ruby on Rails: Talk
I'm going to rebuild my rails app and maybe add react on the front end.    I forget which version of rails I'm using, but I guess it would be best to start over with the latest.

Does anyone know of boilerplate or template that would include starting an app with the react & rails?  (maybe some other useful gems as well)

Thanks,
Joe

Joe Guerra

unread,
Aug 19, 2019, 2:54:04 PM8/19/19
to Ruby on Rails: Talk
I guess this is what I'm looking for?

Stephen Blackstone

unread,
Aug 19, 2019, 3:14:36 PM8/19/19
to rubyonra...@googlegroups.com
You likely just want —webpack=react if using rails 5.1 or higher
Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e66ae529-9607-4952-9798-cc229591f9bd%40googlegroups.com.

Joe Guerra

unread,
Aug 19, 2019, 3:23:29 PM8/19/19
to Ruby on Rails: Talk
Thanks.

Can I add react to my existing project or should I start over?


On Monday, August 19, 2019 at 3:14:36 PM UTC-4, Stephen Blackstone wrote:
You likely just want —webpack=react if using rails 5.1 or higher
Sent from my iPhone

On Aug 19, 2019, at 2:54 PM, Joe Guerra <JGu...@jginfosys.com> wrote:

I guess this is what I'm looking for?

https://github.com/reactjs/react-rails

On Monday, August 19, 2019 at 2:48:03 PM UTC-4, Joe Guerra wrote:
I'm going to rebuild my rails app and maybe add react on the front end.    I forget which version of rails I'm using, but I guess it would be best to start over with the latest.

Does anyone know of boilerplate or template that would include starting an app with the react & rails?  (maybe some other useful gems as well)

Thanks,
Joe

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com.

Noel

unread,
Aug 19, 2019, 3:29:28 PM8/19/19
to Ruby on Rails: Talk
    There are at least 4 different ways that I'm familiar with and tons of resources to help you execute the way that works best for you. Here's the ones I've learned from researching:

1. Approach 1 - CDN based inclusion in header

- You can include it just as a link on the html pages you want to include some React functionality. This is as simple as putting it in the header of the pages.

2. Approach 2 - React Front-end/Rails API backend (pre-existing app)

- Convert controllers into API folders with namespacing technique and create the front-end `client` as shown in Approach 3.

3. Approach 3 - React Front-end/Rails API backend

- This approach works by creating a rails api
rails new myapp --api

- Within the directory of the app run
create-react-app client

- Install foreman gem, create Procfile with the following:
RAILS: bundle exec rails s -p 3001
REACT
: cd client && npm start
 (caveat: If deployed on Heroku, you may need to change `REACT` to `web`.)

- Run servers by
foreman start

- You will need something like axios in node to make the front-end `client` talk to the rails backend but this works.

4. Approach 4 -React-rails gem install
- This approach, I cannot speak to because it seemed the most .... coupled. In the back of my mind, I tend to think this couples react to rails in a way I, at this level of my knowledge, would not be able to decouple if I were to revert to something else or use Vue or stick to normal html requests.

Forgive me giving my opinion on that last one, if someone has more insight on the gem approach, I'd be happy to hear it.



On Monday, August 19, 2019 at 2:14:36 PM UTC-5, Stephen Blackstone wrote:
You likely just want —webpack=react if using rails 5.1 or higher
Sent from my iPhone

On Aug 19, 2019, at 2:54 PM, Joe Guerra <JGu...@jginfosys.com> wrote:

I guess this is what I'm looking for?

https://github.com/reactjs/react-rails

On Monday, August 19, 2019 at 2:48:03 PM UTC-4, Joe Guerra wrote:
I'm going to rebuild my rails app and maybe add react on the front end.    I forget which version of rails I'm using, but I guess it would be best to start over with the latest.

Does anyone know of boilerplate or template that would include starting an app with the react & rails?  (maybe some other useful gems as well)

Thanks,
Joe

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com.

te...@datatravels.com

unread,
Aug 19, 2019, 5:27:19 PM8/19/19
to rubyonra...@googlegroups.com



Another approach is simply to have two completely separate apps: A REACT JS app deployed on Express (google "Create React App on Express") and a separate Rails app, deployed separate to separate servers (/dynos). (It's two separate apps!)

It's not a matter of "Can Rails serve up a React app via the asset pipeline (5.1/5.2) or webpack (6+)?" -- of course it can -- the answer is yes— but should you? 

These days I build out two separate apps even (a React front-end and a Rails backend) even when starting from scratch and even knowing that webpack is default in Rails 6 and that Rails is perfectly capable of serving up the React front-end. 






To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/774f99b0-1647-432f-855b-3d0079ab15ff%40googlegroups.com.

Douglas Lovell

unread,
Aug 20, 2019, 9:54:34 AM8/20/19
to Ruby on Rails: Talk
Here is an open source project on GitHub that combines React with Rails:


It takes a monorepo approach, with the front-end JS code next to the back-end Rails. To integrate, it simply has the JS build (uses Parcel) output the transpiled, bundled javascript into the Rails assets/javascripts directory. It names the output without a fingerprint, because Rails asset pipeline will add one.

The idea was to keep it as simple as it can possibly be and have it work cleanly. It doesn't use the react-rails gem. It doesn't use separate repositories or servers. All of these gymnastics for scale are aspirational. Few projects ever reach the point of scale, especially when bogged-down in the gymnastics.

Joe Guerra

unread,
Aug 22, 2019, 10:20:58 AM8/22/19
to Ruby on Rails: Talk
Thanks.

I found a portfolio app that runs on react.  Got it working locally, unfortunately can't figure out how to publish it to heroku.  (  I did follow a tutorial, most tutorials don't seem to work...)

Brent Mulligan

unread,
Aug 22, 2019, 5:20:32 PM8/22/19
to Ruby on Rails: Talk
Is it an issue with the Heroku build failing? You may need to insert the heroku/nodejs buildpack infront of your heroku/ruby buildpack if it did not happen automatically. You can check by running `heroku buildpacks`, it should list something like 1. heroku/nodejs, 2. heroku/ruby.

Joe Guerra

unread,
Aug 23, 2019, 3:11:28 PM8/23/19
to Ruby on Rails: Talk
I was able to publish the create-react-app my-app   --> right below...


but I was wrapping my head around getting this portfolio up and running so I can add a few of my web projects online.  (of course, I'd edited it a bit, lol)

Reply all
Reply to author
Forward
0 new messages