Mongoid and CanCan Integration

Have someone try to rewrite CanCan ActiverRecordAddtions for Mongoid http://github.com/ryanb/cancan/blob/master/lib/cancan/active_record_additions.rb

Sincerely, Alexey Zakharov

+5
source share
1 answer

I managed to get CanCan and Mongoid (version 2) to work well with the rails 3 application. There are still some errors here and there related to the conditions in the resolution definition (ability model).

I just put the contents of this gist into a file in config / initializers:

The hash of the conditions is almost the same as that of ActiveRecord:

# can only manage own account
can :manage, User, :_id => current_user.id

, Mongoid:: Criteria, :

# can only manage own account
can :eat, Cake do
  current_user.jobs.any?{ |job| job.title == 'Peasant'}
end
+9

All Articles