DEV Community

Kimberly Kohel-Hayes
Kimberly Kohel-Hayes

Posted on • Originally published at kak79.github.io

Creating a Single Page React Application with a Rails Back-End

Start by making a directory with a descriptive name for your application or website.

terminal

Type the following in your terminal to initialize your backend if you are using rails as an api. The ‘-T’ means no testing and the ‘—api’ changes it from a full rails application to an api.

terminal

Change directory into your backend. Do a git add and commit and open your editor. Open your gemfile and add cors and your serializer.

terminal

gemfile

Go to config/initializers/cors.rb and uncomment lines 8 – 16. Change origins type to ‘*’. In your terminal do a git add and commit.

cors file

Change directory up one to your application directory. Type the following into your terminal to initialize your frontend.

terminal

terminal

The last thing you need to do is make two remote git repositories for your frontend and backend. Go to your git repository page and click ‘new’.

new repo

You don’t want to use a template. The name should be the same as the name of your frontend. If it is open source, make it public. Click ‘Create Repository’.

new repo

This is a directory with a git repository already created, so you want to use that option. Copy that code and go to your terminal. Paste it on the command line in your terminal and hit enter.

Repeat the previous two steps for your backend.

You are now ready to create a single page react app or website.

Top comments (1)

Collapse
 
beyarz profile image
Beyar

The --api flag was new to me, really cool!