What is Pundit or CanCanCan in Rails?

Answer

Pundit and CanCanCan are popular authorization gems. Pundit uses plain Ruby policy classes (PostPolicy) with methods like update? and destroy? that return true/false. In the controller: authorize @post checks if the current user can perform the action. CanCanCan centralizes authorization in a single Ability class: can :update, Post, user_id: user.id. Check with can?(:update, @post) or authorize! :update, @post. Pundit is preferred for complex, object-level authorization; CanCanCan for simpler role-based access.