10 things I add to every Rails app
Tags: rails, webdev, opensource, productivity
Published: 2021-10-02 16:25:19

I end up creating a lot of Rails apps, and each time I get started I often find myself wanting to add similar features or gems that I’m using in other projects. 

Here’s a short list of 10 of the most common things I add to every Rails app. 

## 1. Tailwind CSS

I’ve been using Tailwind now for almost 2 years, I am super productive with it and urge you to give it a try if you haven’t yet. 

*As Adam the founder says...*
> If you can suppress the urge to retch long enough to give it a chance, I really think you'll wonder how you ever worked with CSS any other way.

Check out my post below for the best way to use Tailwind with Rails.

{% post https://dev.to/phawk/the-best-way-to-run-tailwind-css-on-rails-302c %}

## 2. Authentication (Devise)

Unless the project has really specific authentication requirements (like nine.shopping’s auth code approach), I’ll use [devise](http://github.com/heartcombo/devise) to manage logins. 

Alongside this, [devise_masquerade](https://github.com/oivoodoo/devise_masquerade) is a fantastic plugin to use with your admin area, allowing you to login as other users. This is helpful for debugging account specific issues etc.

## 3. Email systems

Wether it’s just for ‘forgot password’ emails, pretty much any Rails app I am building is going to send email. There are two handy tools I use for this.

### Letter opener web

[This gem](https://github.com/fgrehm/letter_opener_web) makes sure you don’t embarrasingly send emails to real users whilst developing or testing, life-saver!

### Postmark

[Postmark](https://postmarkapp.com) is a service I have been using for years! It’s really easy to integrate into Rails using their [postmark-rails gem](https://github.com/wildbit/postmark-rails), plus the product is great, easy to use and very reliable.

## 4. Admin system

I try to make all of my products as self-serve as possible, requiring as little of my time to set up accounts or keep the product running. 

Because of this, having an in-depth admin system to allow me to check on things, block malicious users or make billing changes is necessary. 

I usually tend to create these from Scratch, but moving forward I’ve started to use thoughtbot’s [administrate](https://administrate-demo.herokuapp.com) gem. It sticks to the Rails conventions of controllers and routing, so it’s easy to customise and add new functionality to.

## 5. Tests

I am a big fan of TDD and having decent test coverage, this gives me confidence in continuously deploying code and ultimately helps me to develop apps faster.

For testing I use [RSpec](https://github.com/rspec/rspec-rails), along with [shoulda-matchers](http://github.com/thoughtbot/shoulda-matchers) for easily testing model relations & validations.

I use Rails built-in fixtures instead of something like FactoryBot. This is purely for performance reasons, fixtures allow your tests to run much, much faster. Ultimately, I find a fast test suite is more useful and interrupts my workflow a lot less.

## 6. Rubocop

Sticking with the automated testing side of things, I like to use rubocop to make sure my code is consistent and it also catches some common issues with my code.

I usually follow the [Shopify Ruby styleguide](https://ruby-style-guide.shopify.dev) with a few minor tweaks. 

## 7. Sentry

Next up is error monitoring with [Sentry](https://sentry.io). Exceptions usually happen in production when real users get a hold of your code, and making sure these are tracked helps a ton in seeing what’s going on and fixing it!

## 8. Sidekiq

I often don’t set this up right away, but within the first week or two of development comes the time for background jobs. I like to stick with what I know and [Sidekiq](https://sidekiq.org) along with it’s web interface is easy to use and reliable. 

## 9. Metamagic

[This one](https://github.com/lassebunk/metamagic) is a small, but very useful gem. It helps set page titles, meta keywords and even open graph tags for sharing on social sites. This is a must if you have a lot of publicly accessible pages and want to start doing some SEO.

```ruby
<% meta(title: "Sign in to your account") %>
```

## 10. Rack attack

The final gem I like to include in all projects is [rack-attack](https://github.com/rack/rack-attack). This is a rate limiting tool which is great for throttling dangerous actions in your app to prevent bot attacks or other malicious users. 

It works great with APIs, but I also like to use it for login/sign up pages too, like so:

```ruby
Rack::Attack.throttle("authentication/ip", limit: 30, period: 1.hour) do |req|
  if req.post? &&
       %w[/users/sign_in /users/sign_up /users/password].include?(
         req.path
       )
    req.ip
  end
end
```