Creating a new Rails app is super easy by itself. And, creating a Rails app set up as an API is not much different.

Because we are planning on deploying our app to Heroku we need to set it up with PostgreSQL as the database.The default database in Rails is SQLite, but it is not supported by Heroku

Let’s start!

1) Make sure your Rails version is up to date

Run the following line in your terminal to update Rails

gem update rails

and then this line to get the current version of Rails

rails -v

2) Create the Rails API with PostgreSQL

rails new <<APP_NAME>> --api --database=postgresql

_Replace the _

<<APP_NAME>>

_ with the actual name of your app_

  • **rails new **—createa new Rails app
  • **- -api **— initialize the new app as an API. This means the newly created app will not have any views. And the ApplicationController will inherit from ActionController::API instead of ActionController::Base
  • **-- database=postgresql **— And, as you can probably guess, this last part sets up the app to use PostgreSQL as the database

#ruby-on-rails #api #postgresql #heroku #coding #software-development #backend #ruby

How To Connect Ruby on Rails API, PostgreSQL And Heroku
1.35 GEEK