Plymouth Software Logo

3 Ways to Keep Your Ruby on Rails Apps Healthy

Written by Chris • 27 April 2017

Ruby on Rails is a great framework for building modern web applications. But as with any technology, things move on quickly. Without proper care and attention, the web apps and sites you build using Rails can start to degrade. This means slow pages, security vulnerabilities and your users seeing error screens.

As building and supporting Rails apps is a core part of my business, I've adopted a few tools and techniques to ensure that the apps I build and manage are easy to maintain and improve.

Here are 3 things you can do today to keep your Ruby on Rails apps in great condition:

1. Check for Code Smells

A code smell is a section of code in your app that indicates a deeper underlying problem. The problem might be a bug, or a something that has the potential to lead to bugs, such as duplicated blocks of code, or several levels of nested conditions.

Code smells are dangerous for your app because as the amount of code increases, so to does the risk of errors creeping into the code. Catching code smells early and often can help to reduce this risk, and make your code much easier for you (and other developers) to maintain in the future.

RubyCritic is a great tool for identifying code smells and bad practice. You can install it easily by adding the following to your app's Gemfile:

# Gemfile
gem 'rubycritic', require: false, groups: [:development, :test]

Once that's done, just bundle install and run rubycritic against your app's code:

$ cd /path/to/your/app
$ bundle install
$ bundle exec rubycritic --format html

After a while, RubyCritic will generate a report on your app's code quality. If the report doesn't open automatically, you'll find it in your app's tmp/rubycritic folder:

$ open tmp/rubycritic/overview.html

The reports show code smells that Rubycritic has identified. Use the reports as a guide to improve your app's codebase.

2. Scan for security holes

Rails does a lot to protect you from exposing your app to security holes. But like any software, new vulnerabilities are discovered all the time. Keeping your app's version of rails up to date with a supported release is critical to protecting your app and your users.

Similar to Rubycritic for codesmells, we can use tools like brakeman, you can easily scan your app's codebase for security vulnerabilities and known issues. To get started with brakeman, install it as a gem:

$ gem install brakeman

Then jump into your app's code and run the brakeman command:

$ cd /path/to/your/app
$ brakeman

Brakeman will then report on various levels of issues in your code, allowing you to improve the security of your app instantly.

3. Set up Monitoring

Finally, once your app is out in the wild, you'll want to know if anything goes wrong. Errors can occur anywhere - and you definitely don't want them to be silent (to you).

StatusCake Dashboard

StatusCake's monitoring dashboard.

There are lots of different monitoring services out there - with a range of prices - that will help you monitor your app. Several of them, such as StatusCake, Sentry and Rollbar offer free plans to get you started.

There are also several types of monitoring, from availability checks (as provided by StatusCake and Pingdom) through error reporting (Sentry and Rollbar) and performance monitoring (Skylight and New Relic).

To get started, you can start with simple availability and error checks, as they're going to give you the instant coverage that your app needs. Most of the tools are easy to setup, either through registering a URL or dropping a gem and API key into your app's code.

As your user–base and site traffic increases, you should look at performance monitoring tools to keep an eye on how well your app is responding to customers, and highlight any bottlenecks or opportunities for caching.

Next Steps

Keeping a production app in top condition is an ongoing task. To find out more about keeping your app's healthy, and how to make the process easier with tools and systems, check out my new courses at