Junior Track Roadmap

ActionController: rescue_from

This course follows the one rescue_from line in this app's ApplicationController, which catches ActiveRecord::RecordNotFound and renders a custom not-found page. It covers the with: and block forms, how handler arity decides whether the exception is passed, and why declaration order outranks specificity when several handlers match. It also looks at the ActiveRecord exception family under is_a?, Rails' default mapping of RecordNotFound to a 404, and what happens when no handler matches or a handler fails. The last lesson is a small simulator of the search algorithm.

What you'll learn

  • ✓How one rescue_from line on ApplicationController turns a bad slug into a custom not-found page
  • ✓The with: and block forms, and how handler arity decides whether the exception is passed in
  • ✓Why the most recently declared handler wins, and how handlers are inherited
  • ✓How is_a? matching covers a whole exception family, and when to name one exact class
  • ✓How Rails maps RecordNotFound to a 404 and what a custom rescue_from adds
  • ✓What happens when no handler matches or the handler itself raises
Free preview · Lesson 1 4 min read

rescue_from: this app's one line, from a bad slug to a custom page

Course and lesson pages in this app are found by slug, not by numeric id. The query objects behind them:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...