I am a self-taught web developer and this is my first production Ruby on Rails application with a real user base. I love coding, and I love my dog. So, I wanted to give back to the grassroots organization where I adopted my dog from in Mexico by building them a web application to make their process of linking adopters with dogs easier.
This application has been very successful so far, enabling 41 adoptions in its first 6 months. However, I still have a lot to learn and always appreciate feedback. My curiosity for learning led me to provide this codebase to Jason Swett from Code with Jason to review on his live webinar twice in 2023 (so far). Thank you Jason! It was a great experience to learn from you and others on the call about how the code could be refactored for improvement.
Live Site: Baja Pet Rescue
The dog rescue organization has limited time and resources. They have been using Facebook and Instagram to post new dogs and get interest from adopters. This has been working, but is not ideal because:
I met with the stakeholders to learn about their challenges and needs and then conceptualized a solution to address the above challenges. This was a great exercise in turning business needs into application logic.
The solution had to be simple, easy to maintain and manage, and provide a more cohesive flow and experience for both staff and adopters alike. It had to make use of out of the box technology with a low monthly overhead.
I decided that a Ruby on Rails application would be a suitable technology because it enables rapid development and its REST framework provides all of the required functionality. I chose a PostgreSQL database because it is robust and works readily with Ruby on Rails and Heroku, where the production application lives. Last, I opted to use the SendGrid app on Heroku to manage SMTP for mail, and Amazon S3 for image hosting.
These are just some of the documents put together before writing any code:
The application has the following features:
Dependencies
This project has benefited from front and back end contributions. More contributors of all skill levels are welcome.
Picking up an issue:
Making Pull Requests:
git clone <ssh or https url>
git remote add upstream <ssh or https url>
git checkout -b <branch name>
git push origin <branch name>
rails test:all
.When you make a pull request, the GitHub Actions pipeline will run the test suite against your changes and will notify you of pass or fail. You can check the logs for errors, if any. Once the pipeline passes, your pull request will be reviewed and there may be feedback or questions related to your code, so please be prepared to follow up on those. Pull requests are usually reviewed daily. add bullets to the beginning of this set of instructions for an open source github repo for making contributions, and make sure the bullets achieve the
To set this application up locally:
rails -v
to ensure you have Rails 7.0.3 installedrbenv versions
or rvm list rubies
and confirm that Ruby 3.1.1 is installedpsql --version
to ensure you have PostgreSQL 12.12 installed (make sure you have a user and password)git clone <'SSH Key'>
to download application locallybundle install
to install gems (you may have to change gem 'sassc-rails' to gem 'sassc', "~> 2.1.0")bundle exec figaro install
config/application.yml
as ENV variables e.g., DATABASE_USERNAME: "username"
DATABASE_PASSWORD: "password
rails db:setup
to create the database, load the schema, and load seed datarails s
to run the local serverlocalhost:3000
in web browser to access the applicationSetting Up Staff Users
A user account is associated with either an adopter account or staff account.
Staff accounts by default are verified: false
and belong to a placeholder organization, organization_id: 1
.
Therefore, you will need to do the following things in rails console
before you can access the full functionality of staff.
1) Create an organization a = Organization.new(name: 'Placeholder')
a.save
2) Create a staff account via the app UI
3) Find that user account by finding the user_id
e.g., User.find_by(email: 'enter email here')
4) Find that staff account using the user_id
e.g., a = StaffAccount.find_by(user_id: '#')
5) Then set the staff account verified to true a.verified = true
, a.save
Test coverage metrics are generated by the SimpleCov gem. Reading online you will see this gem is not always perfect but it does give a good insight into what code is covered and what is not. There are two things to note:
COVERAGE
. PARALLEL_WORKERS=1
.To run the entire test suite, with coverage: PARALLEL_WORKERS=1 COVERAGE=true rails test:all
.
You can view the HTML metrics in your browser by cd coverage
from the application's root folder, and opening index.html
in your browser.
As I spend more time in Rails and reading about design best practices, one glaring oversight I made in the initial design of this application was not scoping resources (routes and controllers) accordingly. All of my routes and controllers are top level. It works, but if this application were to grow and become more complex, there would be benefit to scoping. For example, the organization_dogs controller should be scoped under an organization, and an adopter profile scoped under an adopter account. This would provide multiple benefits, including:
/organization/dogs
is far more intuitive in terms of understanding these dogs belong to a given organization compared to /dogs
which is configured to point to the organization_dogs#index
controller action.