Revisiting Rails
I have been using various JavaScript frameworks for my site, bigmachine.io, since 2017. That changed in March of 2024, when I threw it all out and rewrote my site using Ruby on Rails.
This is a premium course
And it's amazing and you'll love it, I promise (and guarantee it).
Introduction
We'll take a look at my site, bigmachine.io, and I'll discuss some of the reasons why I chose to use Rails.
Baby Steps: Homepage
Reviewing the basics is always a good thing! Let's setup a home page and review how routing works with Rails.
How Tailwind CSS Works with Rails
Tailwind CSS comes with its own compiler, and scans your template files for the Tailwind classes you're using. It does this for efficiency, but wow it can be confusing!
Tests and Tools
Rails gives you a ton of utility, but I like doing things my own way. In this video, we'll set up Make, our scripts directory (which we'll use later), and a .env file for our secrets
Our First Scaffold
Rails is famous for its scaffolding system and was the very first thing DHH demo'd on stage all those years ago. Are they still useful? I think so! Let's see why.
Setting Up Spina
Installing Spina is reasonably straightforward, but there are some nuances (like routing) that you'll need to understand.
The Spina Layout
There's no styling to your pages when you install Spina, which is a good thing, as you'd probably throw it out right from the start. Let's see how to add some style to our site now that our CMS is up and running.
Defining Parts of a Page
Working with any CMS involves concepts and jargon that are nondescript and overused, and Spina is no different. In this video we'll get to know what Parts are, and how they fit into Pages.
Creating a Sales Page: The Repeater
There a few ways to structure a more complex page with Spina, so let's use the example of a long form sales page and see what we can make!
Creating a Sales Page: The Layout
In my explorations, I found that using Repeaters for each section of my page was the most flexible option, though, yes, probably not what was intended.
Importing Data With Migrations
If you're trying to port existing data into Spina, Rails migrations might be your best choice. You can read records from an existing database, your existing CMS, a CSV or a JSON dump.
Making Your Own Embed
The Trix editor is, in a word, "basic". It's also extensible, which comes in very handy when you want to do things like add code samples and Vimeo videos.
In The Real World
We've cover most of the Spina concepts which should set us up for success. That said, you will probably not want your entire site controlled by this package.
Installing Devise
When it comes to authentication, most people in the Rails world use Devise. Let's install it and see how it works.
Using Passwordless Login
I don't like storing passwords, even if they're hashed. You don't like remembering them, so let's setup a simple email link system.
Logging Out and Registering On the Fly
Let's see how to logout with a single click, and what might get in our way. We'll also ensure that users can register on the fly.
Adding Social Login With OmniAuth
Social login is imperative for web and mobile applications, so we're going to plug in OmniAuth, allowing our users to authenticate with Google and GitHub.
Integrating Devise and Spina
Logging in twice is a pain! Let's ditch the Spina auth system and use our own Devise one.
Flexing Make
I love using Make, especially when it comes to working with my database.
Using Scaffold With Existing Data
Scaffolding is a major productivity booster with new applications - but you can also use it to speed up your rewrite with existing data.
Scaffolding Everything
Now that we understand scaffolds, let's create some for the main tables in our database.
Many to Many Associations
Many to many associations are common in the database world, and working with them on forms (and with models) can be a pain. Rails makes this easy.
Editing Many to Many Records
Rails gives us some great helpers that save so much time, and you're about to meet one of them: collection_check_boxes.
More Complex Many to Many
Some many to many relationships are a bit more complex, such as relating customers to products through invoices (for instance). Let's see how to do this in Rails using a "has many through" relationship.
A Look at Rails Tests
Testing in Rails is extremely simple - the generators do a lot of it for you! In this video we'll have a look at what these generated tests look like.
Filtering Routes
Controllers have a set of "hooks", if you will, called filters. You can run code before, after, or both.
Some Tips and Tools
Let's close out The Rewrite section with some tips and tools. Some of you might be using MongoDB, or just not dig the ActiveRecord pattern. This is OK.
Deployment Considerations
How and where you deploy your site is a highly subjective thing, based on cost and experience. I'll share what I do, just for fun.
Setting Up A Dokku App and Database
Setting up Dokku is all about executing some remote commands. In this video, we'll set up our app container and database, and finally push our existing tables and data.
Preflight Check
We're just about there! Our app container and database are setup, now we just need our code to live on the server.
The First Deployment
If you've worked with Rails, you probably know that the first deployment is usually a matter of herding 100 or so cats. Still the same.
Setting Up S3 CDN
We don't want our CMS images served from our disk in production, so we need to set up a CDN. I'll use S3 as that's what I know.
Wrapping Up
We're all done - but was it worth it? Being honest: both yes, and no.