FindFurryFriend Project (part 1) - Rails API (github repo, models, migrations, seed data)

Meghan Elizabeth
4 min readMay 3, 2021
Photo by Chewy on Unsplash

I’m creating a new project in order to continue learning about react and redux! It’s going to be a petfinder clone and i’m calling it FindFurryFriend! One of my goals for this project is to use the petfinder api. I also want to be able to save animal images to the database so I’m going to setup active storage. FindFurryFriend will have a Ruby on Rails backend and React/Redux frontend.

FindFurryFriend is going to start off with two models- a Shelter model (that will have many pets) and a Pet model (pets will belong to a shelter).

In this blog I will be demonstrating how I created the github repo, Ruby on Rails API- migrations, models and seed data.

Creating Ruby on Rails backend API

Since I’m only utilizing Ruby on Rails as a backend in order to spit out some JSON I only need to create it as an API. Also, I decided to use postgreSQL for this project because I’m hoping to deploy it using heroku.

In the terminal:

rails new find_furry_friend_backend--database=postgresql--api

This command will create all the folders we need in order to get started! After its creation I want to connect it to github.

Creating the Github Repo

I created a new repo by going to github and clicking on the appropriate link. Then the below image pops up and I named the repo and clicked “Create Repository”

After creating the repository for FindFurryFriend, I needed to connect the Rails API that’s on my local machine, to the remote github url that was just created. This is accomplished by typing the below info into the terminal:

git init
git commit -m "initial commit"
git remote add origin https://....... (whatever github put here)
git branch -M main
git push -u origin main

Shelter Models and Migrations

After connecting to github, I decided to make the models and migrations (starting with Shelter). Since convention is to keep the master branch clean and working, I created new branches while building out features.

In the command line:

git co -b shelter_model
rails g model Shelter name street_address city state zipcode email phone
git add .
git commit -m “Shelter model and migration initial setup”
git push

Now in github compare, create and merge the pull request (as shown below). Then delete the branch.

  1. Click compare & pull request

2. Click create pull request

3. click merge pull request

4. click confirm merge

5. click delete branch

Then, check to see if the commits have been merged by looking at the folders in github. If the appropriate folders show they were updated a couple seconds ago, then they have updated.

Lastly, in my terminal I wanted to go back to my main branch and update my branches. (if you type “git branch” in the terminal you can see all the branches and what branch you’re currently on)

So, in the terminal:

git co main
git pull

Pet Model and Migrations

Next, I completed the same steps as above for the Pet model and migrations.

In the command line:

git co -b pet_model
rails g model Pet shelter:belongs_to name animal_type breed size gender age color photo good_with_children:boolean good_with_dogs:boolean good_with_cats:boolean house_trained:boolean vaccinated:boolean
git add .
git commit -m “Pet model and migration initial setup”
git push

Then, compare, create, merge the pull request and delete the branch in github (same steps as above).

Setting up active storage

I’m going to want to have pictures of pets saved to the database so I setup active storage

run rails active_storage:install

It will create migrations for two new tables in your database, active_storage_blobs and active_storage_attachments

Migrations

Since i’m using postgreSQL I need to create the database before migrating:

rails db:create && rails db:migrate

Associations & Seed data

My Shelter model has_many pets and my Pet model belongs_to Shelter. In order to test out my associations I created seed data and ran rails db:seed in the terminal.

rails db:seed

After my database had seed data, I opened up rails console and tested to see if the associations were working.

Summary

✅ Created new rails API

✅ Created github repo

✅ Created models and migrations

✅ created associations

✅ Created seed data

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response