module CanCan::ModelAdditions::ClassMethods

def accessible_by(ability, action = :index, strategy: CanCan.accessible_by_strategy)

Here only the articles which the user can update are returned.

@articles = Article.accessible_by(current_ability, :update)

An alternative action can optionally be passed as a second argument.

other scopes or pagination.
result is returned. Since this is a scope it can be combined with any
If the user does not have permission to read any articles then an empty
Here only the articles which the user is able to read will be returned.

@articles = Article.accessible_by(current_ability)

is usually called from a controller and passed the +current_ability+.
can perform a given action on. The action defaults to :index. This
Returns a scope which fetches only the records that the passed ability
def accessible_by(ability, action = :index, strategy: CanCan.accessible_by_strategy)
  CanCan.with_accessible_by_strategy(strategy) do
    ability.model_adapter(self, action).database_records
  end
end