title: CanCan: abilities in database
body: <p>I wonder what are the pros/cons of the two first code blocks at <a href="https://github.com/ryanb/cancan/wiki/Abilities-in-Database" rel="nofollow">https://github.com/ryanb/cancan/wiki/Abilities-in-Database</a>:</p>
  
  <pre><code>def initialize(user)
    can do |action, subject_class, subject|
      user.permissions.find_all_by_action(aliases_for_action(action)).any? do |permission|
        permission.subject_class == subject_class.to_s &amp;&amp;
        (subject.nil? || permission.subject_id.nil? || permission.subject_id == subject.id)
      end
    end
  end
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>def initialize(user)
    user.permissions.each do |permission|
      if permission.subject_id.nil?
        can permission.action.to_sym, permission.subject_class.constantize
      else
        can permission.action.to_sym, permission.subject_class.constantize, :id =&gt; permission.subject_id
      end
    end
  end
  </code></pre>
  
  <p>Both seem fine to me... Maybe method #1 is less performant? Maybe method #2 is less flexible?</p>