Member-only story

Starting a Rails back end from scratch.

Alex Duterte
1 min readSep 28, 2020

--

Looking to create a Rails backend from scratch? In this following quick start guide, we’ll cover creating a new API backend, the database and migration, model, and controller files.

From the console we can run

rails new myappname --api

Alternatively, if you are looking to use postgresql as your database, we can run

rails new myappname --api --database=postgresql

Creating resources

A quick way to create your controllers, models, migrations etc, is to use “rails g resource”

rails g resource
#can also type out rails generate resource

Let’s say we have a User model. We can create all the files needed with one line.

rails g resource User name:string email:string password: string

This will create

users_controller.rb in controllers
user.rb in models
also this will create the migration file in your db>migration folder

After you create all your models we can run

rails db:migrate

This will run your migration files.

Now your ready to create your seed data and set your relationship in your model files.

--

--

Alex Duterte
Alex Duterte

No responses yet