By now you've used many different gems with Rails and this exercise will have you connect previous knowledge with new knowledge as you get a chance to use the react-rails gem. This gem allows you to build React components as a part of your Rails JavaScript and serve it in a component, react_component, to be used in a regular ERB file.
- Implement a connection between a Ruby on Rails back-end and React front-end.
- Understand the pros and cons of different approaches of connecting Ruby on Rails back-end with React front-end.
To get a local copy for this project and running follow these simple example steps.
- You need to have git installed in your machine.
- Install a recent version of Postgres.
- Already install Rails
- Already insatll React
- use PostgreSQL database
$ rails new rails-react-tutorial --webpack=react -d=postgresql
$ cd rails-react-tutorial # Move into the application directory
- Now run these commands to install everything.
$ bundle install
$ rails webpacker:install
$ rails new rails-react-tutorial --webpack=react -d=postgresql
$ rails webpacker:install:react
$ rails generate react:install
$ yarn install
$ https://github.com/sja-thedude/hello-rails-react.git
$ cd hello-rails-react
$ rails db:create # or
$ rake db:create
- Rubocop gem
$ bundle init
$ bundle install
- Stylelint package
$ npm init -y
$ npm install
$ npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x
- Run linter
$ rubocop .
$ npx stylelint "**/*.{css,scss}"
- In auto-correct mode, RuboCop will try to automatically fix offenses:
$ rubocop -A # or
$ rubocop --auto-correct-all
$ npx stylelint "**/*.{css,scss}" --fix
- We can now run:
$ rails s # or
$ rails server -p3000 # to visit http://localhost/
- To see React-Router working:
$ ./bin/webpack-dev-server # enables auto-webpacking
- To restart the server
$ sudo service postgresql restart
- You can now visit
http://localhost:3000
to view your new website!
$ rails generate controller static index
$ rails generate controller api/messages index
$ rails generate react:component Greeting greeting:string
$ rails generate react:component App
- Redux Thunk
$ Redux Thunk
- Logger for Redux
$ npm i redux-logger
- React Redux Loading Bar
$ npm i react-redux-loading-bar
- To push the Migration into the database
$ rails db:migrate
- We use the seeds.rb file to records in the database
- To drop, create a table and to migrate and send the seed into the database:
$ rails db:drop db:create db:migrate db:seed
- To check available routes
$ rails routes
This project is build with:
👤 Syeda Juveria Afreen
- GitHub: @sja-thedude
- Twitter @sja_thedude
- LinkedIn sja-thedude
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
- Credit to Gregoire Vella on Behance, the author of the original design guidelines
This project is MIT licensed.