title: Rails 4 - exporting routes to CSV
body: <p>I'm developing an ecommerce app and I have a csv export feature which exports all product details like name, price, etc. Each product is in one row with a column for each product attribute. I want to add a column to the file which will contain the url of each product. The reason I want this is so I can use this as a product feed that can be submitted to various shopping sites.</p>
  
  <p>Here is my export code in the controller.  How do I add a column called route to this? I don't have a route column in the model.</p>
  
  <pre><code> #controller
   def productlist
    @listings = Listing.all
  
     respond_to do |format|
       format.html
       format.csv { send_data @listings.to_csv(@listings) }  
     end
   end
  
   #model
      def self.to_csv(listings)
    wanted_columns = [:sku, :name, :designer_or_brand, :description, :price, :saleprice, :inventory, :category]
  
    CSV.generate do |csv|
      csv &lt;&lt; ['Product_ID', 'Product_title', 'Designer_or_Brand', 'Description', 'Price', 'SalePrice', 'Quantity_in_stock', 'Category'] + [:Image, :Image2, :Image3, :Image4]
  
      listings.each do |listing|
        attrs = listing.attributes.with_indifferent_access.values_at(*wanted_columns)
        attrs.push(listing.image.url, listing.image2.try(:url), listing.image3.try(:url), listing.image4.try(:url)) 
  
        csv &lt;&lt; attrs
  
      end
  
    end
  end
  </code></pre>