accessible_by and mongoid: should use $nin instead of $ne #842

thehappycoder opened this Issue Mar 22, 2013 · 1 comment


None yet

2 participants


class Ability
include CanCan::Ability

SUPERADMIN_CLIENTS = %w[radionet xf miscxf]

def initialize(user)
user ||=

if user.superadmin?
  can :manage, :all
elsif user.admin?
  can :read, [Device, Transport]

if user.admin?
  can :index, Client
  can [:show], Client, :name.nin => SUPERADMIN_CLIENTS
  cannot [:manage], Client, name: SUPERADMIN_CLIENTS
  cannot :create, Client


Client.accessible_by(current_ability).asc(:created_at) at controller's index action generates this:
MOPED: QUERY database=mon_development collection=clients selector={"$query"=>{"name"=>{"$ne"=>["radionet", "xf", "miscxf"]}}, "$orderby"=>{"created_at"=>1}} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.6049ms)

But in reality it should be using $nin


Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment