Junior Track Roadmap

Authorization: Pundit

Pundit is a Ruby authorization gem that this app never installed. The course reads Pundit's conventions from its GitHub README: one policy class per model, initialize(user, record), question-mark permission methods and an ApplicationPolicy base. It then covers the controller helpers authorize and policy_scope and the shared Pundit::NotAuthorizedError rescue. Next it reads the policies this app built by hand, the other files in app/policies/, and how their shape compares with Pundit's. It closes with the costs and benefits of adopting the gem and a small Ruby challenge.

What you'll learn

  • ✓Pundit's naming convention, policy class shape and ApplicationPolicy base
  • ✓How authorize, policy_scope and the Pundit::NotAuthorizedError rescue work in controllers
  • ✓How this app's hand-built access-control policies are written and called
  • ✓The difference between access-control policies and domain-rule policies in app/policies/
  • ✓What adopting Pundit would cost and change, including the policy_class: option
Free preview · Lesson 1 3 min read

Pundit's conventions, from its own docs: a policy class per model

Pundit is a widely used Ruby authorization gem, over a decade old and still maintained. This app's Gemfile and Gemfile.lock have no pundit line; the app never installed it. Before comparing anything, this course reads Pundit's conventions from its GitHub README (github.com/varvet/pundit), the way…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...