Gems that Rock 2019

Michael Hayes
Add Jam.
Published in
5 min readApr 10, 2019

--

Over 4 years ago we wrote a post with the terribly witty name ‘Gems that Rock’ — our collection of often used Gems across our rails projects that we had made into a Rails template called the ‘Jam Jar’.

It’s now 2019, we’ve dropped the puns and we no longer maintain our own Rails template (more on that later), but there are a collection of Gems we use all the time - so we thought it was time for another go at summing them up in a blog post.

Sorcery

Github

“Magical Authentication for Rails” sums it up pretty well.

For a long time, we used Devise for authentication. It was the gold standard for authentication in rails, being quick to get running and widely used. As time went on we found it imposes too much opinion on your authentication and when we wanted ‘something’ different it was a headache.

With Sorcery, you need to do a bit more config but we also have a greater degree of freedom. This helps for projects where you might want to use a service like AccountKit from Facebook or the rails app is just being used as an API.

Letter Opener

Github

With a Rails app, there’s high probability you’re going to need to send emails (for things like a welcome message, password reset and notifications). In development, you don’t want to actually send an email and, with the Letter Opener gem, you don’t have to.

Instead, you can easily preview emails in your browser instead of sending it. This means you don’t need to set up email delivery in your development environment, and you no longer need to worry about accidentally sending a test email to someone else’s address. Such a time saver.

Simple Form

Github

Rails forms made easy. Forms can be a pain no matter what you’re developing in but if you get a good package that helps with validations, styling and building the form it helps massively take the pain out of it.

For Rails projects, we’ve been using Simple Form. Pass in the attribute you want and it will make a form using the right type of input for the given attribute ie you give it an integer and SimpleForm will use a number input. Or if your attribute name maps to an input type (like ‘email’ or ‘password’) it will correctly render the needed input HTML. Magic.

Data Confirm Modal

Github

Want to confirm a user action? For example to make sure a destructive action is actually wanted like deleting a repository on GitHub. One way of doing it is by using the built-in confirm() in the browser, although it's a bit ugly and inconsistent across browsers.

Better than the stock browser modal

This gem makes it easy to do confirm modals using the bootstrap modal styling. You can even pass in confirm text, and in the Github example they ask the user to type the repository name to make sure they actually want to delete.

MetaInspector

Github

The modern web is chock full of meta tags. Back in the day, meta tags would just be title and description but in 2019 we now have a host of open graphs tags for everything from images to author and video.

Metainspector is a gem that makes it quick and easy to access meta attributes for an URL. Useful for if you want to ‘unfurl’ a link with your rails app.

Name of Person

Github

From DHH himself. This gem is a simple one that makes it a load easier dealing with English language names. For example when we have a model with first_name and last_name, such as Person, we can use a tonne of useful methods such as:

person.name.full        # => "David Heinemeier Hansson"
person.name.first # => "David"
person.name.last # => "Heinemeier Hansson"
person.name.initials # => "DHH"
person.name.familiar # => "David H."
person.name.abbreviated # => "D. Heinemeier Hansson"
person.name.sorted # => "Heinemeier Hansson, David"
person.name.mentionable # => "davidh"
person.name.possessive # => "David Heinemeier Hansson's"

Administrate

Github

Sometimes you just need a quick CRUD interface for some of your models. A quick way to edit a product list or to manage users. Sure, there are other more feature-full options, such as ActiveAdmin, yet we find Administrate works well in giving a nice looking admin with little effort.

Run the installers, set up a couple of dashboards and off you go. Worth checking out.

Why don’t we use our Rails template?

We found that although we have a host of commonality between Rails projects its highly likely each one will have its own quirks or requirements so we found we had to customise a lot of it anyway.

Then there’s the overhead of keeping the template up to date with what our current preferred ways of working are. Like when we moved from Devise to Sorcery, that didn’t happen overnight, but as we got more frustrated with Devise and more enticed by Sorcery.

As a small team, we weren’t getting the benefit in speed for starting new projects vs the overhead of upkeep. Instead, we keep a list of gems we like in a Slack post and pick and choose as we set up each project. This works for us now, but won’t scale, so we would love to hear what others in the Rails community do — do you use a template? If so, how do you keep it up to date?

Add Jam are a small team doing digital product development from our studio in Glasgow. We make our products using Rails, React, React Native, Swift and Kotlin. Get in touch to learn more about what we do — https://team@addjam.com

--

--

Founder of @add_jam, creating products on iOS, Android & the Web. I’m a huge F1 & motorsport fan. Also founder of the @RookieOven coworking space in Glasgow.