Skip to content

Instantly share code, notes, and snippets.

@RichStone
Last active August 29, 2021 06:50
Show Gist options
  • Select an option

  • Save RichStone/2eb648f8c1be018d29c049a3737ea33f to your computer and use it in GitHub Desktop.

Select an option

Save RichStone/2eb648f8c1be018d29c049a3737ea33f to your computer and use it in GitHub Desktop.
Start a new Rails app

Start a new Rails app

Spin it up

$ cd code/github

$ rbenv global 3.0.0

$ gem update rails

# Powered by postgres and without minitest
$ rails new APP_NAME -d postgresql -T

$ cd APP_NAME
$ git add .
$ git commit -m"Start Rails app"
$ code .

Fix database

Create the database

$ rails db:create

Fix postgres port

(if needed) Add port: 5433 to config/database.yml

Add essential gems

# Gemfile

# Needs to be available in production to seed your heroku DB:
gem 'faker'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'annotate'
  gem 'factory_bot_rails'
end

# ...

group :development do
  gem 'annotate'
  # ...
end

Update bundle:

bundle

Coding quickstart

$ r g scaffold MODEL_NAME name:string
$ r db:migrate

Add some code to the db/seeds.rb and setup the db:

$ r db:seed

You shall now see the a list of your items on localhost:3000/resource

⚠ If you run into webpacker error (Webpacker::Manifest::MissingEntryError), try this: https://stackoverflow.com/a/67158387/5925094

⚠ If you run into EOFError: end of file reached hitting the resources, kill your Docker Rails apps:

$ docker kill $(docker ps -q)
# Reference: EOFError: end of file reached

To recreate the database:

$ rails db:drop db:create db:migrate db:seed

Deploy on Heroku

$ heroku create APP-NAME
$ heroku run db:migrate db:seed

Recreate database

I don't think you can do db:create/drop but you probably can db:setup.

Connect domain

Subdomain: Create a CNAME record with blub "host" and value of your heroku domain (e.g. app-name.herokuapp.com) inside namecheap and then add your domain to heroku:

$ heroku domains:add blub.richstone.io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment