title: Cancancan authorisation of nested resources
body: <p>I've an Account model which "has many" Users and also "has many" Meters. The Meter object has an account_id column so it's easy to define an ability for this in Cancancan:</p>
  
  <pre><code>if user
    can :crud, Meter, :account_id =&gt; user.account_id
  end
  </code></pre>
  
  <p>However, a Meter also "has many" Parameter. I want to do a similar ability definition, only allowing CRUD access if the parameter belongs to a meter which belongs to the same account as user. </p>
  
  <p>As the Parameter model only has a meter_id column (and not an account_id column), I'm not sure of the best way to achieve this extra level of nesting?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Apologies for being unclear.</p>
  
  <p>My models are as follows:</p>
  
  <pre><code>Account &gt; User (account_id) 
          &gt; Meter (account_id) &gt; Parameter (meter_id)
  </code></pre>
  
  <p>So I'm able to check if user.account_id = meter.account_id, but I'm not sure how to check for a parameter.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>As well as Matt's answer, it's simply a case of including:</p>
  
  <pre><code>  load_and_authorize_resource :meter
    load_and_authorize_resource through: :meter
  </code></pre>
  
  <p>in the Parameter model.</p>