title: Rails 5 with CanCanCan - How to filter list for an index action
body: <p>I'm making a system for study purposes.</p>
  
  <p>This system controls the hospital shifts for the user. An user should only see his shifts.</p>
  
  <p>I'm using CanCanCan for the authorization control.</p>
  
  <p>So for the index page the controller action I have:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
      def index
          @users = User.all
      end
  end
  </code></pre>
  
  <p>In the index.html.erb</p>
  
  <pre><code>&lt;% @shifts.each do |shift| %&gt;
      &lt;% if can? :read, shift %&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;%= shift.date %&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In the ability I have:</p>
  
  <pre><code>class Ability
      include CanCan::Ability
  
      def initialize(user)
          if user
              can :manage, Shift, user_id: user.id
          end
      end
  end
  </code></pre>
  
  <p>I want to show a message to the user if he doesn't have any shifts.</p>
  
  <p>But using the can method in index html page because if the list is not empty but there is no shift the current user can see I can't use an empty method direct in the @shift.</p>
  
  <p>Is it possible to filter the list in the index action in user controller?</p>