Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Uninitialized constant 'Product::CSV'

I have the following Product class which is raising an uninitialized constant Product::CSV exception.

class Product < ActiveRecord::Base   has_attached_file :photo, :styles => { :small => "150*150>" }    def self.import(file)       CSV.foreach(file.path, headers: true) do |row|         product = find_by_id(row["id"]) || new         product.attributes = row.to_hash.slice(*accessible_attributes)         product.save!       end     end   end 
like image 809
venu Avatar asked Jan 25 '14 06:01

venu


1 Answers

You need to require the CSV library.

require 'csv'  class Product < ActiveRecord::Base    # ... end 
like image 88
Nicolas Garnil Avatar answered Oct 08 '22 03:10

Nicolas Garnil