title: Defining abilities with block for action index with CanCan and Ruby on Rails
body: <p>I need to add a filter on users. A user can see other users only if the user belongs to same branch. One user can belong to multiple branches.</p>
  
  <p>I am defining ability with the blocks below. But after referring to documentation and facing an error I got to know that the <code>index</code> method doesn't fit well with defining the ability with block.</p>
  
  <pre><code>#This code is part of initialisation method of ability.rb
  
  can :index, User do |curr_user|
      #check if user belongs to same branch
      !curr_user.branch_ids.index(branch_id).nil?
  end
  </code></pre>
  
  <p>Here is index method of users controller</p>
  
  <pre><code>def index
      authorize! :index, User
  
      @users = User.where(params[:user]).accessible_by(current_ability, :index)
  
      renders :obj =&gt;@users
  end
  </code></pre>
  
  <p>What is some alternative to define abilities to implement this logic in place of defining abilities with blocks?</p>