Skip to content

Instantly share code, notes, and snippets.

@ElliotOlbright
Last active July 19, 2021 21:00
Show Gist options
  • Save ElliotOlbright/1fb48cd54c5de08734f8f0383e6a2574 to your computer and use it in GitHub Desktop.
Save ElliotOlbright/1fb48cd54c5de08734f8f0383e6a2574 to your computer and use it in GitHub Desktop.
Adopt don't shop user stories in consecutive order

Adopt Don't Shop Developement - Due 7/21 10:00pm MST

animal pngs

shouldamatcher

Table of Contents

Rails Set Up

  • Find rails setup here

Database Schema

Screen-Shot-2021-07-15-at-4-57-20-PM.png

Schema Explanation

  1. Shelters have_many Pets

  2. Pets belongs_to Shelter(Pets: foreign_key => Shelter: primary_key)

  3. Pet_Applications belongs_to Pets and Applications(Pet_Applications: foreign_key => Pets: primary_key AND Applications: primary_key)

  4. Pets has_many Applications through Pet_Applications(Applications: foreign_key => Pet_Applications: foreign_key => Pets: primary_key)

  5. Applications has_many Pets through Pet_Applications(Pets: foreign_key => Pet_Applications: foreign_key => Applications: primary_key)

Generate Tables in Terminal

  • shelters
    rails generate migration CreateShelters name:string city:string rank:integer foster-program:boolean
    
  • pets
    rails generate migration CreatePets name:string breed:string age:string adoptable:boolean 
    
  • applications
    rails generate migration CreateApplications name:string street:string city:string state:string zip_code:string application_status:string
    
  • users
    rails generate migration CreatePetApplications status:string
    
  • add timestamps to migration files in db/migrate/<migration-file> directory
    t.timestamps 
    

Add Associations and Dependents

  • add pets to shelters
    rails g migration AddShelterToPets shelter:references
    
    # /app/models/shelter.rb
    
    class Shelter < ApplicationRecord
      has_many :pets 
    end
  • add application to pet_applications
    rails g migration AddApplicationToPetApplications application:references
    
    # /app/models/pet_application.rb
    
    class PetApplication < ApplicationRecord
      belongs_to :pet
      belongs_to :application
    end 
  • add pet to pet_applications
    rails g migration AddPetToPetApplications pet:references
    
    # /app/models/pet_application.rb
    
    class PetApplication < ApplicationRecord
      belongs_to :pet
      belongs_to :application
    end 
  • add applications to pets(through pet_applications)
    # /app/models/pet.rb
    
    class Pet < ApplicationRecord 
      belongs_to :shelter 
      has_many :pet_applications, dependent: :destroy
      has_many :applications, through: :pet_applications
    end 
  • add pets to applications(through pet_applications
    # /app/models/pet.rb
    
    class Pet < ApplicationRecord 
     belongs_to :shelter 
     has_many :pet_applications, dependent: :destroy
     has_many :applications, through: :pet_applications
    end 
    • run migrations in commandline
    rails db:migrate 
    

Seed Database

# /db/seeds.rb
Application.destroy_all
PetApplication.destroy_all
Pet.destroy_all
Shelter.destroy_all

#applications

app1 = Application.create!(name: 'Caroline Tan', street: '2534 Tan Blvd', city: 'Boulder', state: 'Colorado', zip_code: 80204, application_status: 'pending')
app2 = Application.create!(name: 'Ezze Alwfai', street: '1234 fake st', city: 'Lafayette', state: 'Colorado', zip_code: 80328, application_status: 'pending')
app3 = Application.create!(name: 'Marla Shulz', street: '2020 Corona st', city: 'Denver', state: 'Colorado', zip_code: 80218, application_status: 'approved')
app4 = Application.create!(name: 'Matt Kragen', street: '5522 California st', city: 'Denver', state: 'Colorado', zip_code: 80218, application_status: 'approved')
app5 = Application.create!(name: 'Scott Berecki', street: '2222 Studio rd', city: 'Colorado Springs', state: 'Colorado', zip_code: 80907, application_status: 'rejected')
app6 = Application.create!(name: 'Sami Peterson', street: '9341 Chicago st', city: 'Westminster', state: 'Colorado', zip_code: 80305, application_status: 'rejected')
app7 = Application.create!(name: 'Taylor Varoglu', street: '1529 Beard st', city: 'Boulder', state: 'Colorado', zip_code: 80304, application_status: 'approve')
app8 = Application.create!(name: 'Micheal Abbott', street: '6733 Washington st', city: 'Lyons', state: 'Colorado', zip_code: 80540, application_status: 'pending')
app9 = Application.create!(name: 'Ozzie Osmonson', street: '2342 Pesto ln', city: 'Denver', state: 'Colorado', zip_code: 80019, application_status: 'rejected')
app10 = Application.create!(name: 'Carina Sweets', street: '6354 Candy ln', city: 'Longmont', state: 'Colorado', zip_code: 80504, application_status: 'pending')



#shelters

shelter_1 = Shelter.create!(name: "Denver Humane Society",
                            city: "Denver",
                            rank: 1,
                            foster_program: "true")


shelter_2 = Shelter.create!(name: "Boulder Humane Society",
                            city: "Boulder",                        
                            rank: 2,
                            foster_program: "false")


#pets

pet1 = shelter_2.pets.create!(name: "Rex",
                              breed: "Australian Shepherd",
                              adoptable: true,
                              age: 2)

pet2 = shelter_2.pets.create!(name: "Lady",
                              breed: "Shepherd Mix",
                              adoptable: true,
                              age: 1)

pet3 = shelter_2.pets.create!(name: "Osco",
                              breed: "Springer-Spaniel",
                              adoptable: true,
                              age: 4)

pet4 = shelter_2.pets.create!(name: "Jack",
                              breed: "Pitbull",
                              adoptable: true,
                              age: 7)

pet5 = shelter_1.pets.create!(name: "Jibbs",
                              breed: "Pug",
                              adoptable: true,
                              age: 5)

pet6 = shelter_1.pets.create!(name: "Jax",
                              breed: "Lab Mix",
                              adoptable: true,
                              age: 4)

pet7 = shelter_1.pets.create!(name: "Bianca",
                              breed: "Golden Retriever",
                              adoptable: true,
                              age: 2)

pet8 = shelter_1.pets.create!(name: "Beans",
                              breed: "German Shepherd",
                              adoptable: true,
                              age: 9)

pet9 = shelter_1.pets.create!(name: "Stella",
                              breed: "Chihuahua",
                              adoptable: true,
                              age: 12)

pet10 = shelter_1.pets.create!(name: "Penelope",
                              breed: "Bulldog",
                              adoptable: true,
                              age: 12)

seed database

rails db:seed

Heroku Setup

Further setup here Download Heroku here

Initialize Git Repository and Heroku

  • change directories into project, run cd <my-project
  • run in commandline directory git init
  • run heroku git:remote -a 'project_name'

Deploy to Heroku

  • add to git staging area git add .

  • commit to git git commit -m 'commit message'

  • push to github git push origin 'branch-name'

  • push to Heroku git push heroku 'branch-name'

  • if an error for "Failed to push Refs", run: bundle lock --add-platform x86_64-linux -commit and push to heroku again

  • migrate tables to heroku

    heroku run rake db:migrate
    
  • seed tables to heroku

    heroku run rake db:seed
    

Application Layout

Proj2-Flow.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment