Starting a Rails back end from scratch.

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

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.

Fullstack Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store