Let's Build: With Ruby on Rails - Job Board with Payments
Welcome to what I'll be calling my tenth installment to my Let's Build: With Ruby on Rails series. In this build, I'll cover how to build a filterable job board with payments using Stripe as a payment gateway to post new jobs.
More about the app
The basis of the application is a job board where anyone looking to get hired can come and apply for positions. If you are a user or company looking to post a job you can sign up for an account and do so for a fee. We use a combination of the Stripe API and the Stripe Ruby Gem to initialize a charge when a job gets posted.
If there are errors along the way the form will offer error feedback for both the Rails-based form and the Stripe based form.
Stripe has a variety of solutions when it comes to accepting payments securely. There's really no wrong way to do so but some applications may favor alternative approaches. In our case, I opted for Stripe Elements which is a drop-in replacement that allows you to display a form for the credit card of which you can manipulate at will.
Styling it or triggering something to happen upon user input is completely up to you. If you'd rather bypass all of that customization you can always integrate the originally Stripe.js library and or use Stripe Checkout which is as simple as dropping in a form with key-value pairs inside your application.
Kicking off the build
In previous builds I started from scratch by installing and configuring gems as we needed them. In order to save some time, I decided to create a Rails application template. This approach is super useful if you find yourself reaching for the same files, gems, and other various features a Rails app has over and over. In my exact case, I tend to use gems such as Devise, Guard, Bulma, SimpleForm, and more to create the same type of app for these screencasts.
With all of this said I decided to share my template of which I called Kickoff. In the videos I discuss at greater length how everything here works but to make use of it you can download the repo and
cd into it.
From that point, you can create a new Rails app by running
rails new myapp -m template.rb. The
template.rb file is where all the magic happens. It tells our new app how to configure itself and essentially presents a checklist of tasks to perform. This ultimately saves me a load of time!
If you used my template you should be in good shape to kick-off building the job board. The main models we will utilize in this project are the
User model and the
Job will house quite a few fields which are important for any type of job listing online.
Job will feature the following:
- Title -
- Description -
- Logo Avatar - via Carrierwave -
- Website URL -
- Type: Fulltime, Part-Time, Freelance, Contract
- Location -
- User ID -
- Remote ok -
remote_ok: boolean, default: false
- apply_url -
Scaffolding this model is relatively trivial with rails. Fair warning that it's a rather lengthy script to run.
$ rails g scaffold Job title:string description:text url:string job_type:string location:string remote_ok:boolean apply_url:string
Notice how I left out
user_id. We add those later as separate migrations where
avatar is a string-based column and
user_id is an integer-based column.
User will have:
- Name -
- Email -
- Stripe ID -
- Card Type -
- Card Last 4 -
- Card Exp Mo -
- Card Exp Year -
- Expires at -
- Admin -
We don't use a scaffold for Users in this app as Devise does most of the heavy lifting for us. Rather than scaffold any model we just perform a few migrations to get our hands dirty.
The first is an admin column. This column as you can probably guess dictates whether a given user is an admin or not. At the most basic form, we need to make a user an admin bt setting the
admin column to
true. And then in all our views, we can use a clever method to check if this is indeed the case
# show something only admins can see here
If you used my initial Kickoff template you should have Devise all ready to go out of the box. This appends a
name field to our user model but we want to get a bit more information about the user when it comes time to make a purchase. Those extra bits of information include primarily credit card related information. We can add those as a simple migration all at once.
class AddCardInfoToUsers < ActiveRecord::Migration[5.1]
add_column :users, :stripe_id, :string
add_column :users, :card_brand, :string
add_column :users, :card_last4, :string
add_column :users, :card_exp_month, :string
add_column :users, :card_exp_year, :string
add_column :users, :expires_at, :datetime
Now since we are using Stripe charges we don't necessarily require this information on a given user. If you, for example, wanted to add some sort of subscription service to your app you might be better off saving this type of data. For our app, I just wanted to show by example. In future apps, we will look into the subscription model using Stripe and/or Braintree as a merchant.
I think from here it's best to follow along watching the videos. The bulk of implementing a payment gateway into an app is knowing where it will live and how a user must interact with it before, during, and after purchase. With Rails and Stripe, you can hook into parameters and events to build a payment flow of your dreams. This app starts small with charges but I plan to scale more apps to have a subscription type of flow and even possibly utilize Stripe Connect where you can be a merchant who allows each of your users to both send and receive payments using Stripe as well. Until then I hope you enjoyed this build.
If you haven't checked out the previous builds find those linked below:
- Let's Build: With Ruby on Rails - Introduction
- Let's Build: With Ruby on Rails - Installation
- Let's Build: With Ruby on Rails - Blog with Comments
- Let's Build: With Ruby on Rails - A Twitter Clone
- Let's Build: With Ruby on Rails - A Dribbble Clone
- Let's Build: With Ruby on Rails - Project Management App
- Let's Build: With Ruby on Rails - Discussion Forum
- Let's Build: With Ruby on Rails - Deploying an App to Heroku
- Let’s Build: With Ruby on Rails – eCommerce Music Shop
This series has been really fun for me. It probably goes without saying that this has also been a huge undertaking. I appreciate the attention it getting and can't thank you enough if you've already subscribed to my YouTube channel or my weekly newsletter.
Shameless plug time
I have a new course called Hello Rails. Hello Rails is modern course designed to help you start using and understanding Ruby on Rails fast. If you're a novice when it comes to Ruby or Ruby on Rails I invite you to check out the site. The course will be much like these builds but a super more in-depth version with more realistic goals and deliverables. View the course!