Junior Track Roadmap

Controller filters & concerns

This course reads the controller filters and concerns of one Rails app. It starts with the two before_action calls in Admin::BaseController, then covers the order of the callback chain across parent and child classes, and how only: and except: narrow it. It looks at skip_before_action and the app's one CSRF skip, rescue_from and how Rails matches exceptions, and ActiveSupport::Concern in a module, in Rails and in the app. It ends with an unextracted duplication and a plain Ruby challenge.

What you'll learn

  • ✓How before_action registers methods that run before every action of a controller and its subclasses
  • ✓The order of inherited callbacks and how only: and except: limit them to specific actions
  • ✓Why a redirect_to in a before_action stops the chain, through the performed? terminator
  • ✓How skip_before_action removes verify_authenticity_token for one OAuth callback action
  • ✓How rescue_from matches exceptions by class hierarchy, searching handlers from the last declared
  • ✓How ActiveSupport::Concern works with included do and class_methods do blocks
Free preview · Lesson 1 2 min read

Two before_action calls, guarding every admin page at once

This app's app/controllers/admin/base_controller.rb, in full:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...