4 different ways to use react on rails
1. Using only Rails 5 webpack methods
2. Using rails-api mode and react separately
3. Using react_on_rails gem
4. Using react-rails gem
1. Using only Rails 5 webpack methods
- Create a new rails app with this command
rails new lyntour --webpack=react --database=postgresql -T --skip-coffee --skip-sprockets
2. Using rails-api mode and react separately
- Create a new rails app in api mode
rails new _5.1.5_ lyntour-api --api --database=postgresql -T
- Create react app separately on different directory
npx create-react-app lyntour-front
3. Using react_on_rails gem
- create a new rails app with this command
rails new lyntour --webpack=react --database=postgresql -T
- install react_on_rails and install
rails generate react_on_rails:install
bundle && yarn
4. Using react-rails gem
- create a new rails app
rails new lyntour
cd lyntour
- Add webpacker and react-rails to your gemfile:
gem 'webpacker'
gem 'react-rails'
- Now run the installers:
bundle install
rails webpacker:install # OR (on rails version < 5.0) rake webpacker:install
rails webpacker:install:react # OR (on rails version < 5.0) rake webpacker:install:react
rails generate react:install
My preferences are 1 and 2
References
-
Option 2
-
Option 3