Ruby on Rails Tutorial — Heroku API Deployment

Setup

rails new dogs --api -d postgresql

Configuring your Database

default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# Make sure the below reflects your local postgres user
port: 5432
host: localhost
username: test5
password: test5
development:
<<: *default
database: mice_development
test:
<<: *default
database: mice_test
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end

Create a quick API

Dog.create(name: "Sparky", age: 5, breed: "Bulldog")
Dog.create(name: "Spot", age: 5, breed: "Dalmation")
Dog.create(name: "Goldy", age: 5, breed: "Golden Retriever")

Test the Api

Deploy to Heroku

--

--

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