title: Cancan and polymorphism
body: <p>I want to specify rules in ability file for polymorphic associations as follows:</p>
  
  <pre><code> class Ability
    include CanCan::Ability
  
    def initialize(user)
      user ||= User.new # guest user
  
      if user.role? :admin
        can :manage, :all
      elsif user.role? :author
        can :read, :all
        can :manage, [Post, Article], user_id: user.id
        can :manage, Comment, commentable: {user_id: user.id}        
      end
    end
  end
  </code></pre>
  
  <p>I want the user to be able to edit the comment to his posts. But when checking access simple user can still edit other (all) comments.</p>
  
  <p>Is this abilty works for cancan?</p>
  
  <pre><code> can :manage, Comment, commentable: {user_id: user.id}        
  </code></pre>
  
  <p>Thank you for your help!</p>
  
  <p><strong><em>======= update =======</em></strong></p>
  
  <p>Sorry that I forgot to show my ability  checking:</p>
  
  <pre><code>- can? :manage, @post =&gt; Comment
  </code></pre>
  
  <p>And tried to rewrite:</p>
  
  <pre><code>= can? :manage, @post.comments.build
  </code></pre>
  
  <p>but I do not like this cheching, because created empty object</p>