Creating a silent auction using Ruby, SQLite3, and ActiveRecord

Dante Lombardi
3 min readJun 25, 2021

If you’re new to programming like I am some cool practice projects to work on would be to create a simple site that uses Ruby, SQLite3 and ActiveRecord to query backend databases for persistent data maintenance and displaying that data on a front end site. I am creating a simple silent auction site that can help build out my understanding of different frontend and backend tools that are commonly used in web development.

real image of me coding

Create User Stories

Your first steps to take would be to conceptualize your user stories. What is it that you want your site to do? How will users interact with your site and what kind of functionality will you need to build. To start I have laid out a couple of guidelines that I will work towards.

  1. Site will display a list of current active auctions that they can bid on.
  2. User will be able to submit a bid with a bidder name and bid amount.
  3. User will be able to update or a delete a bid on an active auction.
  4. User will be able to end an auction, displaying who the highest bidder is and the winner.

Map Relationships

Once you have a few user stories defined you should start to map out your data and your data relationships, take a few minutes to think about how your relationships will be structured. In my case, a auction can have many bids and many bidders , and a bidder can have many bids and many auctions. A bid belongs to a single bidder and a single auction, and thus is the ‘join’.

If you were to map it out visually it might looks like this:

Auctions > — Bids — < Bidders

Create Your Migrations

Now that you know how your data is going to be structured you can start to create the migrations to create the tables using Rake. I choose to create all the tables in one migration and my tables looked like this:

very imaginative migration name

Notice how I have auction_id and bidder_id under bids, this is so that I can create those associations between these tables.

It can be helpful to check your schema to see that the migration was successful. I had to drop the table my first time and try again in order to get the scheme to load. The old turn it off and turn it back on again trick.

Don’t ask why it works, just be thankful it does.

Now that I’ve created my migrations I will create my associations between the data, with with bidders and auctions having many of bids and each other and bids belonging to both auctions and bidders.

Seed dummy data and test your database

Now that you’ve got you data structure all set up its time to start seeding that data! In my seeds.rb file I will hard code some fake auctions in, as well as create a random sampling of bidders from a bidders name array and some dummy bids using random number generator to create the bid amounts.

Using Rake console you can sample your data to make sure associations are working correctly and that the data sampled is in the correct format. Using this I first noticed that my bidder name was initially instantiated as integer when it should have been a name.

--

--