rails-authorization-cancancan

rails-authorization-cancancan is a skill for Claude Code, Codex from Shoebtamboli/rails_claude_skills. It costs 109 tokens per session (3,656 once invoked), scanned A, original, MIT.

A guide to authorization in Ruby on Rails using CanCanCan, a library for deciding which actions each user may take. It centralizes those permission rules in an Ability class.

In plain words
What is it for?
Use it to define roles and permissions, restrict records in controllers, filter data by user access, and control which interface actions are shown.
Why use it?
It helps keep access rules in one place instead of scattering checks across controllers and screens.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to define roles and permissions, restrict records in controllers, filter data by user access, and control which interface actions are shown.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Shoebtamboli/rails_claude_skills --skill rails-authorization-cancancan
Clone the repo
git clone --depth 1 https://github.com/Shoebtamboli/rails_claude_skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rails-authorization-cancancan

README.md
[![agentmods](https://agentmods.dev/badge/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan/github.svg)](https://agentmods.dev/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan)
Your own site
<a href="https://agentmods.dev/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan"><img src="https://agentmods.dev/badge/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for rails-authorization-cancancan

Your own site · 80×15
<a href="https://agentmods.dev/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan"><img src="https://agentmods.dev/badge/skills/shoebtamboli/rails_claude_skills/rails-authorization-cancancan.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 109 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,656 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00109 $0.03656
Opus 5 $0.00055 $0.01828
Sonnet 5 $0.00022 $0.00731
Haiku 4.5 $0.00011 $0.00366

Measured 12d ago against content hash 1141f2b4c756, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

rails-authorization-cancancan scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

lib/generators/claude/skills_library/rails-authorization-cancancan/SKILL.md · 604 lines

How it starts

The opening of the file, as written. The whole thing — 604 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rails Authorization with CanCanCan

CanCanCan is a popular authorization library for Rails that restricts what resources a given user is allowed to access. It centralizes all permission logic in a single Ability class, keeping authorization rules DRY and maintainable.

Quick Setup

# Add to Gemfile
bundle add cancancan

# Generate Ability class
rails generate cancan:ability

This creates app/models/ability.rb where all authorization rules are defined.

Core Concepts

Defining Abilities

The Ability class centralizes all permission logic:

# app/models/ability.rb
class Ability
  include CanCan::Ability

  def initialize(user)
    # Guest users (not signed in)
    can :read, Post, published: true
    can :read, Comment

    # Signed-in users
    return unless user.present?

    can :read, Post
    can :create, Post
    can :update, Post, user_id: user.id
    can :destroy, Post, user_id: user.id

    can :create, Comment
    can :update, Comment, user_id: user.id
    can :destroy, Comment, user_id: user.id

    # Admin users
    return unless user.admin?

    can :manage, :all  # Can do anything
  end
end

Best Practice: Structure rules hierarchically (guest → user → admin) for clarity.

Actions and Resources

Standard CRUD Actions

:read    # :index and :show
:create  # :new and :create
:update  # :edit and :update
:destroy # :destroy

:manage  # All actions (use carefully!)

Custom Actions

can :publish, Post
can :archive, Post
can :approve, Comment

Multiple Resources

can :read, [Post, Comment, Category]
can :manage, [User, Post], user_id: user.id

Ability Conditions

Hash Conditions

# Simple equality
can :update, Post, user_id: user.id

# Multiple conditions (AND logic)
can :read, Post, published: true, category_id: user.accessible_category_ids

# SQL fragment (use sparingly)
can :read, Post, ["published_at <= ?", Time.zone.now]

Block Conditions

Read the full file on GitHub · 604 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 604 lines · 109 tokens per session scan A 1141f2b4c756

Subscribe to this mod's changes

rails-authorization-cancancan is a skill published in the GitHub repository Shoebtamboli/rails_claude_skills (16 stars, last pushed 2mo ago), licensed MIT. It adds 109 tokens to every session and 3,656 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories