How to Set Up a Rails SAML Identity Provider

Security Assertion Markup Language (SAML) is a protocol for single sign-on. SAML handles communication between a service provider (SP) and an identity provider (IdP). The identity provider acts as an authentication and identification mechanism for service providers.

In this post, I’ll walk you through setting up your Rails application as a SAML IdP. This post is not intended to take a deep dive into the SAML protocol.
Read more on How to Set Up a Rails SAML Identity Provider…

Code Generation for Rails Utility Scripts

It seems that on every Rails project I work on, I end up writing utility scripts that make changes to the production data in some way or another. Perhaps it’s pre-loading hundreds of user accounts for a customer that wants to provide a spreadsheet of users, or populating an account with fake data that can be used for a demo, or manually fixing a data integration issue with an external system. Often, this requires parsing and processing a source file (like a CSV file). Read more on Code Generation for Rails Utility Scripts…

Active Record Aggregate Fields via Sub-Selecting Scopes

I was recently working on a piece of code from a legacy Rails application. An unusually large number of queries being run on a particular page let me know there was an N+1 query lurking.

The application was an online assessment platform dealing with assessments, questions, and responses. The question listing page was simply asking each question if it’s locked—which happens if it has any responses. So what’s the best way to query for lots of questions and their locked status? Read more on Active Record Aggregate Fields via Sub-Selecting Scopes…

Run a Local Rails Script on Heroku

Heroku provides a convenient command line interface for executing snippets of Ruby code remotely. One-liners can easily be piped into the heroku run console command. But what about much longer scripts that you write locally and want to execute in a remote Heroku environment? In this post, I’ll show you how to execute a long Ruby/Rails script in a remote Heroku environment.

Read more on Run a Local Rails Script on Heroku…

Adding Google Charts to your Active Admin Application

Active Admin is a fantastic library for building an administrator interface for a Rails application. Not only does it make creating CRUD pages incredibly simple, but it also allows for custom views–something I discovered recently when I needed to create a dashboard page that included several charts.
Read more on Adding Google Charts to your Active Admin Application…

A Few Tips For Getting Started With Rails

Rails does a lot of work for you. This is often beneficial, but when it makes assumptions that aren’t right for your app, it can be frustrating. In this post, I’ll discuss a few issues that can arise when you get started creating models, along with some easy solutions to them. Oh, and before I get too far, I should note that the code here assumes you are using Rails 5.
Read more on A Few Tips For Getting Started With Rails…

Testing Data Migrations in Rails

When working on a Rails project, you will inevitably need to move data around in your database. Some join table value will need to be moved into its own table or what have you. When approaching these kinds of migrations, there are two major complications: future-proofing and testing. In this post, let’s walk through an example migration.
Read more on Testing Data Migrations in Rails…

Uploading Files in Rails Using Paperclip and Active Admin

I recently came across a situation where I needed to be able to upload a file to a Rails server with Active Admin. I did a quick search on Google and found this post by Job, a fellow Atom.

Our use cases were a little bit different, though. He was storing the file contents directly in the database, whereas I needed to be able to uplaod a firmware image file to the server’s filesystem, parse the file name, and perform some validations on the file. I decided to use the Paperclip gem to manage the file processing and storage. Using Job’s advice on Active Admin file uploads, I expanded his example to incorporate Paperclip.
Read more on Uploading Files in Rails Using Paperclip and Active Admin…

A Minimalist Guide to Customizing ActiveAdmin Forms

ActiveAdmin has saved a huge amount of time on our current project, and I highly recommend it for quickly giving non-technical people administrator access to your Rails app.

Some of the documentation is great, and there are lots of methods you can use to customize, but there are also some out-of-date red herrings, some things that require learning about Formtastic, etc. So here’s a minimalist guide to customizing ActiveAdmin forms relying more on Ruby and logic than on the unique ins and outs of ActiveAdmin.
Read more on A Minimalist Guide to Customizing ActiveAdmin Forms…