During my time at Flatiron School, I built several projects using a Ruby on Rails API backend with a JavaScript frontend. As more languages are picked up, it can be easy to forget some of the nuances of other languages in your repertoire. For those of you who learned Ruby on Rails but can’t remember how to get a JavaScript/Rails API project started, I’ve created this guide to help jog your memory!

Database and Project Creation

First things first, let’s install our database, PostgreSQL. To do this, open your terminal and type the following commands:

brew install postgres

brew services start postgresql

gem install pg

Now, let’s build our backend and create the project itself! Enter the following command in the terminal and wait for the request to process:

rails new [name-of-api] — api -G -T -d=postgresql

Our reasons for including G, T, and d?

-G because we don’t want to initialize it as a git repository

-T because we don’t need tests

-d selects a specific database (in this case, we want PostgreSQL)

Next, cd into the project directory, and we’ll create our database so we can store all of our data for the project. Make sure PostgreSQL is running on your computer (click on the elephant icon, select “Open Postgres”, and initialize. Don’t try the next step until you see Postgres successfully running, like so:

In your terminal, enter:

rails db:create

You should then see two new cylinder files in PostgreSQL; a development file and a test file with the name of your api.

#api #ruby-on-rails #postgresql #backend-development

Creating a Ruby on Rails API
1.10 GEEK