# Useful Ruby Gems

*Published on April 25, 2022*

---


Although Rails provides great defaults out-of-the-box, you can easily extend it with Ruby gems. Here are some gems that I find myself using every time I start a new Rails project.

### [Semantic Logger](https://logger.rocketjob.io/)

Semantic Logger is a feature-rich logging framework, and replacement for existing Ruby & Rails loggers.

```ruby
gem "amazing_print"
gem "rails_semantic_logger"
```

### [Better Errors](https://github.com/BetterErrors/better_errors)

Provides a better error page for Rails and other Rack apps. Use with&nbsp;`binding_of_caller`&nbsp;to include source code inspection, a live REPL and local/instance variable inspection for all stack frames.

```ruby
group :development do
  gem "better_errors"
  gem "binding_of_caller"
end
```

### [Rails-dotenv](https://github.com/bkeepers/dotenv)

Provides a simple way to load environment variables from&nbsp;`.env`.

```ruby
gem 'dotenv-rails', groups: [:development, :test]
```

- Add your application configuration to your .env file in the root of your project (git ignore it):

```php
S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE
```

- Whenever your application loads, these variables will be available in ENV:

```ruby
config.fog_directory  = ENV['S3_BUCKET']
```

### [Debugger](https://github.com/deivid-rodriguez/pry-byebug)

Update (2025): Use the new [debug](https://github.com/ruby/debug) gem instead.

Enable step-by-step debugging and stack navigation in Pry.

```ruby
gem 'pry-byebug'
```

- Set up the shortcuts

```ruby
➜  touch ~/.pryrc
➜  code ~/.pryrc

if defined?(PryByebug)
    Pry.commands.alias_command 'c', 'continue'
    Pry.commands.alias_command 's', 'step'
    Pry.commands.alias_command 'n', 'next'
    Pry.commands.alias_command 'f', 'finish'
end
```

### [Annotate\_Models](https://github.com/ctran/annotate_models)

Annotate Rails classes with schema and routes info.

```ruby
group :development do
  gem 'annotate'
end
```

- Annotate the models

```bash
cd ~/projects/writer
annotate
```

### [RSpec-Rails](https://github.com/rspec/rspec-rails)

_Update (2025): I use Minitest now._

RSpec for Rails. Behaviour Driven Development.

```ruby
group :development, :test do
  gem 'rspec-rails', '~> 5.0.0'
end
```

- Check out the&nbsp;[usage instructions](https://github.com/rspec/rspec-rails#installation).

### [FactoryBot-Rails](https://github.com/thoughtbot/factory_bot_rails)

_Update (2025): I use Rails fixtures now._

A library for setting up Ruby objects as test data.

```ruby
group :development, :test do
  gem "factory_bot_rails", "~> 6.2"
end
```

- Read the&nbsp;[Getting Started](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md)&nbsp;guide.
- Create one factory for each class that provides the simplest set of attributes necessary to create an instance of that class.
- If you’re creating ActiveRecord objects, that means that you should only provide attributes that are required through validations and that do not have defaults.
- Other factories can be created through inheritance to cover common scenarios for each class.

### [Rubocop](https://github.com/rubocop/rubocop)

A Ruby static code analyzer and formatter, based on the community Ruby style guide.

```ruby
group :development do
  gem 'rubocop', require: false
end
```

- Add a config file named&nbsp;**.rubocop.yml**
- Disable certain checks

```text
Style/StringLiterals:
  Enabled: false
```

* * *

Here’s the resulting Gemfile with a short description of each gem.

```ruby
# Semantic Logger is a feature rich logging framework, and replacement for existing Ruby & Rails loggers.
gem "amazing_print"
gem "rails_semantic_logger"

group :development, :test do
  # Step-by-step debugging and stack navigation in Pry
  gem 'pry-byebug'

  # A Ruby gem to load environment variables from `.env`.
  gem 'dotenv-rails', groups: [:development, :test]

  # # RSpec for Rails. Behaviour Driven Development.
  gem 'rspec-rails', '~> 5.0.0'

  # A library for setting up Ruby objects as test data.
  gem "factory_bot_rails", "~> 6.2"
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"

  # Provides a better error page for Rails and other Rack apps.
  gem "better_errors"

  # Includes source code inspection, a live REPL and local/instance variable inspection for all stack frames.
  gem "binding_of_caller"

  # Annotate Rails classes with schema and routes info
  gem 'annotate'

  # A Ruby static code analyzer and formatter, based on the community Ruby style guide.
  gem 'rubocop', require: false
end
```

