title: How can I select all active products with variants in Rails query
body: <p>I have two models: <code>Product</code> and <code>Variants</code>. <code>Prouduct has_many :variants</code> and <code>Variant belongs_to :product</code>. I need a query, that will select all active products with variants. I tried this:</p>
  
  <p><code>@products = Product.joins(:variants).where('products.active =?, true)</code>, but it doesn't seem to be the solution. Doing in the view something like this:</p>
  
  <pre><code>&lt;% @products.each do |product| %&gt;
    &lt;% if proudct.variants.any? %&gt;
      &lt;!-- Do something here... --&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>is not an option. Can you help me to build a correct query? Thanks ahead.</p>