Ruby on Rails Monday, August 19, 2019

    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.
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.

No comments:

Post a Comment