title: Rails - Iterating through records witin a method
body: <p>I have a method that just iterates through various models, printing out the model attributes: </p>
  
  <pre><code>def self.get_attributes(options = {})
    options[:model_name].find(:all, :conditions =&gt; {:generated_at =&gt; options[:start_date]..options[:end_date]}).each do |p|
    puts p.options[:col_name]
  end
  </code></pre>
  
  <p>to call the method:</p>
  
  <pre><code>start_date = DateTime.strptime(params[:start_date], '%m/%d/%Y').beginning_of_day.strftime("%Y-%m-%d %H:%M:%S")
  end_date = DateTime.strptime(params[:end_date], '%m/%d/%Y').end_of_day.strftime("%Y-%m-%d %H:%M:%S")
  get_attributes({:model_name =&gt;  Revenue, :col_name =&gt; "revenue",  :start_date =&gt; start_date, :end_date =&gt; end_date})
  </code></pre>
  
  <p>I have tried passing in the column name as a string and variable. When passed as a variable I get an <code>undefined variable</code> exception. As is above, I get an <code>undefined method 'col_name'</code> exception. How can I interpolate the column name within the above method? </p>