Skip to content

.

└── charlotteresnick.dev

└── a blog about my journey to software engineer

Week Eleven - Ruby On Rails

General, React, Ruby, Rails1 min read

This week consisted of regular expressions, recursion, a hash table lesson, rails basics, another lesson on graphs, and a how-to on hooking up Rails to React.

Interested in the exact steps to create a React app that talks to your Rails app? You've come to the right place.

Here goes:

  1. Create a React app client:
1create-react-app client
  1. Install the foreman gem (you only have to do this once!):
1gem install foreman
  1. Create a Procfile:
1touch Procfile
  1. Toss these lines in your Procfile:
1web: cd client && npm start
2api: bundle exec rails s -p 3001
  1. Start foreman:
1foreman start -p 3000
  1. At this point, both of your servers should load - open up localhost:3000 and localhost:3001.

  2. Working? Great. Now quit out of your servers.

  3. In client/package.json, add a proxy:

1"proxy": "http://localhost:3001/"
  1. Start foreman again:
1foreman start -p 3000
  1. Now get to making fetch requests from the frontend to the backend!
© 2020 by charlotteresnick.dev. All rights reserved.
Source