Skip to content

Create a Rails App with PostgreSQL and GitHub

Use this when starting a new Rails project that should use PostgreSQL and live on GitHub.

Check the active Ruby and Rails versions before creating the app. These should come from the Ruby version managed by mise.

Terminal window
ruby -v
rails -v

Install and activate Ruby with mise if the project needs a newer Ruby version. This is usually a one-time setup step for each Ruby version.

Terminal window
mise use ruby@latest
ruby -v

If rails -v shows an older version than expected, install the latest Rails gem for the active Ruby version.

Terminal window
gem install rails
mise reshim
rails -v

mise reshim refreshes command shims so the rails command points at the newly installed gem executable.

Create the app with PostgreSQL as the database.

Terminal window
rails new APP_NAME -d postgresql
cd APP_NAME

Add these flags when creating the app if the project needs a specific frontend, database, or setup style.

Terminal window
rails new APP_NAME -d postgresql -j esbuild -c tailwind

Options marked (default) do not need to be specified when using the standard Rails defaults.

FlagUse
-d postgresqlUse PostgreSQL as the database.
-d mysqlUse MySQL as the database.
-d sqlite3(default) Use SQLite as the database.
FlagUse
-j importmap(default) Use import maps for JavaScript.
-j esbuildUse esbuild for JavaScript bundling.
-j rollupUse Rollup for JavaScript bundling.
-j webpackUse webpack for JavaScript bundling.
FlagUse
-c tailwindUse Tailwind CSS.
-c bootstrapUse Bootstrap.
-c bulmaUse Bulma.
-c sassUse Sass.
FlagUse
--apiCreate an API-only Rails app.
--skip-testSkip Rails test files.
--skip-system-testSkip system test files.
--skip-action-mailerSkip Action Mailer.
--skip-action-mailboxSkip Action Mailbox.
--skip-action-textSkip Action Text.
--skip-active-storageSkip Active Storage.
--skip-hotwireSkip Hotwire.
--skip-jbuilderSkip Jbuilder.
--skip-bundleCreate the app without running bundle install.

Create the local development and test databases.

Terminal window
bin/rails db:create

Start the Rails server and open the local app in the browser.

Terminal window
bin/rails server

Rails initializes Git by default. Add the generated files and commit the app baseline.

Terminal window
git status
git add .
git commit -m "Initial Rails app"

Create an empty GitHub repo first, then add the SSH remote and push main.

Terminal window
git branch -M main
git remote add origin git@github.com:USERNAME/REPO.git
git push -u origin main

After main is pushed, create dev for regular development work.

Terminal window
git checkout -b dev
git push -u origin dev