title: Exporting CSV data from Rails
body: <p>I'm working to export csv data from rails. I'm following the tutorial here: <a href="http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast" rel="nofollow">http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast</a></p>
  
  <p>In my controller I have:</p>
  
  <pre><code>  def show
      # @company is being provided correctly.
      @groups = @company.groups
      render text: @groups.to_csv
    end  
  </code></pre>
  
  <p>In my group.rb model:</p>
  
  <pre><code>  def self.to_csv
      Rails.logger.info "Hello World"
      CSV.generate do |csv|
        csv &lt;&lt; column_names
        all.each do |product|
          csv &lt;&lt; product.attributes.values_at(*column_names)
        end
      end
    end
  </code></pre>
  
  <p>The issue is the browser is outputting just the following: </p>
  
  <pre><code>#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
  </code></pre>
  
  <p>The model method appears to be being ignored, even after a rails restart. Any ideas what's wrong here? Thanks</p>