Create a new Rails API and configure it to use PostgreSQL
Since learning Ruby, Ruby on Rails and PostgreSQL I recently learned that Rails will default to other SQL variants installed on my machine first like SQLite which I used in a recent project before moving on to PostgreSQL.
I'm sure I'm not the only one out there who didn't make sure that their Rails database wasn't configured to use Postgres automatically so I did some digging around to make this post to show you how to just that in 2 easy steps.
Step 1
Make your project folder and cd
into it.
mkdir example-app
cd example-app
Step 2
Create the Rails backend with a PostgreSQL database using this command:
rails new my-example-app --api --database=postgresql
Bonus
After cd
ing and running bundle install
in your new rails folder you're free to set up things like git if you want your work all in one repo. You can set up your React frontend in a subfolder with:
npm install --prefix client
Now you will never have the issue of wondering if you're using anything other than PostgreSQL for your Rails app! However the real work of actually building the Rails app has just begun but you can pat yourself on the back for getting this task done.
Top comments (0)