A Ruby on Rails Wishlist App — Mechanical Keyboard Group Buys

Ciara Swann
4 min readMay 4, 2021

--

Welcome to Hoshii!

Inspiration

As a self-proclaimed keyboard enthusiast, a huge part of the hobby is staying up to date with the latest group buys. Group buys in the mechanical keyboard community involve a sale that only runs for a few weeks (or on a first come first serve — FCFS — basis). While someone could just lurk in keyboard forums and subreddits to get information, it can be difficult to keep track of what group buys are currently running or upcoming. While there are a couple of applications that compile upcoming group buys, I sought to build upon these applications with additional features.

Features:

  • Third-party sign up and log in using Devise
  • Filter, Sort, & Search
  • Wishlist

Using Devise for User Authentication

The Devise gem with OmniAuth took the most time to get up to speed on. There were some helpful video tutorials that I found through a quick google search, but the documentation for the gem was by far the most useful resource for learning how to use the gem. Once the gem was up and running, the methods (current_user, user_signed_in?) and views (registration, partials) that it provided were extremely helpful in building out the rest of my app.

For this project, I chose to set up OmniAuthentication with Github.

To get your devise methods working, make sure to add the following to the top of your controllers.

before_action :authenticate_user!

If you’re not familiar with before_action, it’s essentially a new syntax for before_filter. In Rails, there are CRUD actions such as index, new, create, show, and destroy. By putting this line at the top of your controller you are saying: before taking any actions, execute the following method. The authenticate_user! method in Devise, authenticates the user, and if it cannot do so, routes to the login/signup view.

Seeding the Database

To seed my database with the data I needed to get my application working, I used the Rest-Client gem. The Rest-Client gem is a REST and HTTP client that uses simple requests (such as ‘get’) to access and utilize data.

I defined five methods within my seed.rb file: seed_groupbuys, price_to_f, set_category, if_null,and set_status. Four of the five methods are meant to format the data that is created through the seed_groupbuys method.

seeds.rb

Sort & Search Using Scope Methods

Once I had seeded my database, I wanted a simple way for users to be able to sort through all the data and easily find what they were looking for. To add sort features to my application, I used a couple of scope methods in my Groupbuy model. Scope methods are great for keeping an application DRY (Don’t Repeat Yourself). By defining them in my model, I was able to use them in other files in my application and they help so much with keeping code clean and readable.

For my search feature, however, I did use a class method. While I could have easily used a scope method, I used a class method primarily to solidify my understanding of how the method will function. Sometimes it's just helpful for me to break things down, to gain a deeper intuition into how my code works.

Groupbuy Model

Wishlist

The primary feature of my application is the wishlist. I wanted a way for users to be able to save group buys, so they could easily go back to the application at a later date and keep track of group buys status. Users can create, read, update, and delete (CRUD) their own personal wishlists.

Using the browse view, a user can choose from their created wishlists, then click on a heart icon located on each group buy card to add the group buys to the selected wishlist. At the top right of a group buy card, a little heart identifies if a group buy has already been added to a wishlist.

Browse group buys and add to your wishlist.

Please feel free to check out my Github repo here.

--

--

Ciara Swann

Software Engineer Intern. Coach @ Rewriting the Code