Create a Rails App with PostgreSQL and GitHub
Use this when starting a new Rails project that should use PostgreSQL and live on GitHub.
Verify Ruby and Rails
Section titled “Verify Ruby and Rails”Check the active Ruby and Rails versions before creating the app. These should come from the Ruby version managed by mise.
ruby -vrails -vInstall Ruby with mise
Section titled “Install Ruby with mise”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.
mise use ruby@latestruby -vInstall or update Rails
Section titled “Install or update Rails”If rails -v shows an older version than expected, install the latest Rails gem for the active Ruby version.
gem install railsmise reshimrails -vmise reshim refreshes command shims so the rails command points at the newly installed gem executable.
Create the Rails app
Section titled “Create the Rails app”Create the app with PostgreSQL as the database.
rails new APP_NAME -d postgresqlcd APP_NAMEOptional rails new flags
Section titled “Optional rails new flags”Add these flags when creating the app if the project needs a specific frontend, database, or setup style.
rails new APP_NAME -d postgresql -j esbuild -c tailwindOptions marked (default) do not need to be specified when using the standard Rails defaults.
Database
Section titled “Database”| Flag | Use |
|---|---|
-d postgresql | Use PostgreSQL as the database. |
-d mysql | Use MySQL as the database. |
-d sqlite3 | (default) Use SQLite as the database. |
JavaScript
Section titled “JavaScript”| Flag | Use |
|---|---|
-j importmap | (default) Use import maps for JavaScript. |
-j esbuild | Use esbuild for JavaScript bundling. |
-j rollup | Use Rollup for JavaScript bundling. |
-j webpack | Use webpack for JavaScript bundling. |
Stylesheets
Section titled “Stylesheets”| Flag | Use |
|---|---|
-c tailwind | Use Tailwind CSS. |
-c bootstrap | Use Bootstrap. |
-c bulma | Use Bulma. |
-c sass | Use Sass. |
Other Utilities
Section titled “Other Utilities”| Flag | Use |
|---|---|
--api | Create an API-only Rails app. |
--skip-test | Skip Rails test files. |
--skip-system-test | Skip system test files. |
--skip-action-mailer | Skip Action Mailer. |
--skip-action-mailbox | Skip Action Mailbox. |
--skip-action-text | Skip Action Text. |
--skip-active-storage | Skip Active Storage. |
--skip-hotwire | Skip Hotwire. |
--skip-jbuilder | Skip Jbuilder. |
--skip-bundle | Create the app without running bundle install. |
Create the databases
Section titled “Create the databases”Create the local development and test databases.
bin/rails db:createCheck the app locally
Section titled “Check the app locally”Start the Rails server and open the local app in the browser.
bin/rails serverMake the first commit
Section titled “Make the first commit”Rails initializes Git by default. Add the generated files and commit the app baseline.
git statusgit add .git commit -m "Initial Rails app"Push main to GitHub
Section titled “Push main to GitHub”Create an empty GitHub repo first, then add the SSH remote and push main.
git branch -M maingit remote add origin git@github.com:USERNAME/REPO.gitgit push -u origin mainCreate and push dev
Section titled “Create and push dev”After main is pushed, create dev for regular development work.
git checkout -b devgit push -u origin dev