title: Export as CSV in Rails with association model values
body: <p>In my project one of the features is to export data as CSV.</p>
  
  <p>I have written a function in the model to do this, which works fine but what if I wanted to export the associated model values in the same CSV file?</p>
  
  <p>I tried multiple methods but didn't succeed. </p>
  
  <p>Product.rb:</p>
  
  <pre><code>has_many :product_other_informations
  
  def self.to_csv
    CSV.generate do |csv|
      csv &lt;&lt; ["Name", "Description", "Tags", "Meta_keywords", "Page_title", "Meta_description", "Slug", "Published_status", "Other_information", "Other_information_value"]
      all.each do |product|
        csv &lt;&lt; [product.name, product.description, product.tags, product.meta_keywords, product.page_title, product.meta_description, product.slug, product.is_published]
      end
    end
  end
  </code></pre>
  
  <p>This is used to export only product values. What do I do if I want to export "product other information" model values in the same CSV?</p>