Systems | Development | Analytics | API | Testing

Sidekiq Unique Jobs: Three Ways to Avoid Duplicates

To avoid duplicate Sidekiq jobs, you have three options: guard enqueues yourself with database flags or a queue scan, use Sidekiq Enterprise’s unique_for option, or add the free sidekiq-unique-jobs gem, which locks jobs in Redis by class and arguments. On Sidekiq 8, sidekiq-unique-jobs 8 with lock: :until_executed covers most cases.

RSpec Tests in Ruby on Rails: Every Spec Type Explained (2026)

RSpec is the most widely used testing framework for Ruby on Rails. With the rspec-rails gem (v8.x, supporting Rails 7.2–8.x), you write model specs for business logic, request specs for controllers and APIs, and system specs for browser flows — plus mailer and job specs. Run the suite with bundle exec rspec. In the first part of this series, we looked at the basics of RSpec and how well it works with Behavior Driven Development in Ruby.

Making the Most of Your Logs in Rails

Rails logs through Rails.logger — on Rails 8.1, a BroadcastLogger that writes tagged lines to STDOUT in production and to log/development.log in development. Six levels exist: debug, info, warn, error, fatal, and unknown; production defaults to info via RAILS_LOG_LEVEL. Good log messages are descriptive, carry context like request IDs, and become structured JSON when machines read them.

Generating Random Numbers in Ruby: rand, Random & SecureRandom

To generate a random number in Ruby, call rand: rand(10) returns an integer from 0–9, rand(1..10) an integer from 1–10, and rand alone a float between 0.0 and 1.0. For security-sensitive values like tokens and passwords, use SecureRandom — rand is predictable. Computers cannot produce truly random numbers by computation alone. A deterministic machine can only produce pseudorandom numbers: a stream that looks random but comes from an algorithm fed with a starting value, the seed.

How to Use Shoulda Matchers with RSpec for Ruby on Rails

shoulda-matchers gives you one-line RSpec and Minitest matchers for common Rails behavior — it { should validate_presence_of(:name) } replaces a hand-written validation spec. Add gem "shoulda-matchers", "~> 8.0" to your Gemfile’s test group, then add the configuration block to spec/rails_helper.rb naming your test framework and library. Version 8 works with Rails 8.1 and rspec-rails 8.

Sidekiq for Ruby on Rails: Setup, Jobs & Monitoring (2026)

Sidekiq is a background job framework for Ruby that processes jobs concurrently on threads, backed by Redis. In Rails, add gem "sidekiq", set config.active_job.queue_adapter = :sidekiq, enqueue with perform_async, and run the sidekiq process alongside your app server. Sidekiq 8 requires Ruby 3.2+ and Redis 7+. That answer covers the mechanics.

Custom Exceptions in Ruby: Classes, Messages & Hierarchies

To create a custom exception in Ruby, define a class that inherits from StandardError: class PaymentError < StandardError; end. Raise it with raise PaymentError, "card declined" and rescue it by class. Inherit from StandardError, not Exception, so a bare rescue still catches it. Pass a default message by overriding initialize and calling super. Ruby’s built-in exception classes describe the language’s failure modes, not your application’s.

Devise for Ruby on Rails: Setup, Modules & Rails 8 Auth

Devise is a full-featured authentication gem for Ruby on Rails, built on Warden. It provides registration, login, password recovery, session timeout, and account locking via 10 composable modules. Install it with bundle add devise, then run rails g devise:install and rails g devise User. It works with Rails 7 and 8; Rails 8's built-in generator covers only simpler needs.

Handling Exceptions in Grape for Ruby: rescue_from and error!

Grape handles exceptions with rescue_from blocks declared on your API class: rescue_from :all catches every exception, while rescue_from ActiveRecord::RecordNotFound targets one class. Inside an endpoint, error!("Not Found", 404) halts with a formatted error, defaulting to status 500. Without a handler, invalid params return 400 and other exceptions bubble up to Rack. This guide covers Grape 3.3. Every response body, status code, and error message was verified on Grape 3.3.5, Rack 3.2.7, and Ruby 3.4.10.

Add an App With Your Coding Agent

You can now ask your coding agent to set up AppSignal in your application. Give it a prompt, let it follow the installation instructions, and watch a checklist fill in as data starts arriving. Installing AppSignal was already straightforward, but it still meant checking your environment, adding the right integration, creating an app, handling credentials, and confirming that telemetry arrived. These are useful checks, but they don't all need your attention.