Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-4cancancancancan

CanCan Ability: can read Class if he can read at leas one Object of class


In cancan to be Able to :read all User for exemple we need

can :read,User

to be able to see a specific instance of the user we need

can :read, User do |user|
    user == something (condition satisfied ==> ability satisfied)
end

Now my question is : is it possible to check if the user can read at least one instance?? i have a menu where i have to show "users" in the menu if he can at least read one instance of a user otherwise not showing anything


Solution

  • This worked for me:

    if User.accessible_by(current_ability,:read) > 0