cancan

https://github.com/ryanb/cancan

Ruby

Authorization Gem for Ruby on Rails.

CanCan::ModelAdapters::ActiveRecordAdapter#conditions

Returns conditions intended to be used inside a database query. Normally you will not call this
method directly, but instead go through ModelAdditions#accessible_by.

If there is only one "can" definition, a hash of conditions will be returned matching the one defined.

  can :manage, User, :id => 1
  query(:manage, User).conditions # => { :id => 1 }

If there are multiple "can" definitions, a SQL string will be returned to handle complex cases.

  can :manage, User, :id => 1
  can :manage, User, :manager_id => 1
  cannot :manage, User, :self_managed => true
  query(:manage, User).conditions # => "not (self_managed = 't') AND ((manager_id = 1) OR (id = 1))"

Source | Google | Stack overflow

Edit

git clone [email protected]:ryanb/cancan.git

cd cancan

open lib/cancan/model_adapters/active_record_adapter.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-CanCan--ModelAdapters--ActiveRecordAdapter-conditions-for-pr


# Commit to git

git add lib/cancan/model_adapters/active_record_adapter.rbgit commit -m "better docs for CanCan::ModelAdapters::ActiveRecordAdapter#conditions"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-CanCan--ModelAdapters--ActiveRecordAdapter-conditions-for-pr

hub pull-request


# Celebrate!