Installation

October 23, 2021 ยท View on GitHub

Add this to your Gemfile:

gem 'cancancan'

and run the bundle install command.

Use the provided command to generate a template for your abilities file:

rails generate cancan:ability

This will generate the following file:

# /app/models/ability.rb

class Ability
  include CanCan::Ability

  def initialize(user)
  end
end

This is everything you need to start. :boom:

All the permissions will be defined in this file. You can of course split it into multiple files if your application grows, but we'll cover that in a later chapter.

Let's now start with the basic concepts: define and check abilities.