title: Each Loop in Rails 4 Controller to create new instance variable
body: <p>I have a parent form (lead) and child form (QuoteMetal) (which is rendered multiple times on the same submit). All the information from the forms gets written to their respective data tables, but I need the information from the child forms to perform a query and return those values. I have the forms created and a controller which writes the information to the data tables. </p>
  
  <p>I need help with making the query results for each of the child forms then accessing them in the views. Here is what I currently have.</p>
  
  <pre><code>class LeadsController &lt; ApplicationController
  
    def index
      @lead = Lead.new
      @quote_metal = @lead.quote_metals.build
    end
  
    def create
      #raise params.inspect
      @lead = Lead.create!(lead_params) #write to data tables (which works)
      @lead.quote_metals.each do |f|
        @metal = Metal.calculate_metal(f).first #here is where my problem is! the     #calculate_metal is the query located in my model
      end
    end
  
    def show
    end
  
  private
  
      def lead_params
          params.require(:lead).permit([:name, ..... 
              quote_metals_attributes: [:id...],
        quote_melees_attributes: [:shape...],
        quote_diamonds_attributes: [:shape...]
        ])
      end
  
  end
  </code></pre>
  
  <p>and the view:</p>
  
  <pre><code>&lt;div class='container'&gt;
    &lt;div class="row"&gt;
      &lt;div class='col-sm-3 col-sm-offset-2'&gt;
        &lt;h3 class="text-center"&gt;Your Search: &lt;/h3&gt;
      &lt;/div&gt;
      &lt;div class='col-sm-5'&gt;
          &lt;h4 class="text-center"&gt;Returning estimates for a &lt;%= @metal.metal %&gt; setting
         weighing &lt;%= @metal.weight %&gt; &lt;%= @metal.unit %&gt;. I am paying
         &lt;%= number_to_currency(@metal.price, precision: 2) %&gt; per &lt;%= @metal.unit %&gt;.&lt;/h4&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>