Ruby on Rails
Monday, August 19, 2019
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.
On Aug 19, 2019, at 3:29 PM, Noel <noelirias@gmail.com> wrote: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:(caveat: If deployed on Heroku, you may need to change `REACT` to `web`.)
RAILS: bundle exec rails s -p 3001
REACT: cd client && npm start- 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 higherSent from my iPhoneI 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 .
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ .e66ae529-9607-4952-9798- cc229591f9bd%40googlegroups. com
--
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-talk+unsubscribe@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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment