# CanCanCan

> The authorization Gem for Ruby on Rails

Source: https://talira.ai/catalog/cancancan-fdzdzsq8
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [security / auth / authorization](https://talira.ai/categories/security/auth/authorization), [languages / ruby / rails](https://talira.ai/categories/languages/ruby/rails)
- Licence: MIT[^2]
- Pricing: Free and open source[^2]
- Free tier: yes[^2]
- Self-hostable: yes[^3]
- API: yes[^4]
- Creator: Ryan Bates created CanCan; Alessandro Rodi has maintained CanCanCan since 2015
- Sponsors: Membean, Goboony, Renuo

CanCanCan is an authorization library for Ruby and Rails that keeps permissions in one or more `Ability` classes: rules like `can :read, Post, user: user` are checked with `can?` and `authorize!` in controllers and views, and `accessible_by` turns the same rules into a database query that fetches only the records a user may access. `load_and_authorize_resource` loads and authorizes the resource for each action of a RESTful controller, and `permitted_attributes` says which attributes a user may change. It continues Ryan Bates's CanCan; Alessandro Rodi of Renuo has maintained it since 2015, and releases came again in October and November 2026 (3.6.2 to 3.7.1) after a gap of more than two years.

## Links

- GitHub: https://github.com/coorasse/cancancan
- Docs: https://github.com/coorasse/cancancan/tree/main/docs

## Problems it solves

- define all my Rails app's permissions in one place instead of scattered across controllers
- fetch only the records the current user is allowed to see, straight from the database
- admins can manage everything, editors only their own posts: role-based rules in Rails
- hide edit and delete links in views from users who can't use them
- load and authorize the record in every RESTful controller action without repeating code
- show a friendly page when someone opens something they aren't allowed to
- let a client change user permissions stored in the database without redeploying
- limit which fields of a record each user is allowed to update
- test my authorization rules in RSpec without going through controllers
- check permissions on nested resources like a project's tasks
- translate access denied messages for each language

## Features

- can and cannot rules in Ability classes, split across files if needed
- can? and cannot? checks in controllers and views
- authorize! raising CanCan::AccessDenied
- accessible_by to fetch authorized records with SQL, with selectable SQL strategies
- load_and_authorize_resource for RESTful and nested resources
- hash conditions, block conditions and scopes
- permitted_attributes and disallowed_attributes
- action aliases and rules compression
- model adapter system: Active Record built in, custom adapters
- RSpec matchers and testing guide
- I18n for unauthorized messages

## Limitations

- Block conditions can't fetch records: accessible_by raises an exception for a rule defined only by a Ruby block, unless you add SQL[^1]

## Capabilities

- Has an API: plan not known

## Trust

Overall: 0.34 out of 1.
Signals: backing 0.35, extensibility 0.20.

- created by Ryan Bates created CanCan; Alessandro Rodi has maintained CanCanCan since 2015
- sponsored by Membean, Goboony, Renuo

Warnings:

- GitHub activity not fetched yet

## Alternatives

- [Pundit](https://talira.ai/catalog/pundit-sdyy04t7.md): Minimal authorization through OO design and pure Ruby classes
- [Apache Casbin](https://talira.ai/catalog/apache-casbin-q0j8c46t.md): An authorization library that supports access control models like ACL, RBAC, ABAC

## Sources

[^1]: https://github.com/coorasse/cancancan/blob/main/docs/define_abilities_with_blocks.md (checked 20 Nov 2026)
[^2]: https://github.com/coorasse/cancancan/blob/main/LICENSE (checked 20 Nov 2026)
[^3]: https://github.com/coorasse/cancancan (checked 20 Nov 2026)
[^4]: https://github.com/coorasse/cancancan/blob/main/docs/README.md (checked 20 Nov 2026)
