title: Passing parameter from view to controller for multiple iteration
body: <p>My controller is retrieving the follow:</p>
  
  <pre><code>def index
      @segments = Segment.all
      @products = Product.all
  end
  </code></pre>
  
  <p>But it is not what I want. I want to iterate products based on its <code>segment_id</code>. Something like this:</p>
  
  <pre><code>def index
      @segments = Segment.all
      @products = Product.where(segment_id: x)
  end
  </code></pre>
  
  <p>The problem is: <strong>how to pass <code>x</code> from view to controller?</strong></p>
  
  <p>My view is:</p>
  
  <pre><code>- @segments.each do |s|
      - @products.each do |p|
          This is a product from #{s.name}.
  </code></pre>
  
  <p>Ok, <strong>where's the issue?</strong> I'm not showing specific products of specific segments. I'm showing products of all segments. What I need is something like this:</p>
  
  <pre><code>- @segments.each do |s|
      - @products(segment_id: s.id).each do |p|
          This is a product from #{s.name}.
  </code></pre>
  
  <p>Can you understand?</p>