我有以下Product类引发uninitialized constant Product::CSV异常.
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
Run Code Online (Sandbox Code Playgroud) 使用gem magick'并使用rails 3.1.0
Fetching gem metadata from http://rubygems.org/.........
Fetching additional metadata from http://rubygems.org/..
Resolving dependencies...
Using rake (10.1.1)
Using multi_json (1.8.4)
Using activesupport (3.1.0)
Using bcrypt-ruby (3.0.1)
Using builder (3.0.4)
Using i18n (0.6.9)
Using activemodel (3.1.0)
Using erubis (2.7.0)
Using rack (1.3.10)
Using rack-cache (1.0.3)
Using rack-mount (0.8.3)
Using rack-test (0.6.2)
Using hike (1.2.3)
Using tilt (1.3.7)
Using sprockets (2.0.4)
Using actionpack (3.1.0)
Using mime-types (1.25.1)
Using polyglot (0.3.4)
Using treetop (1.4.15)
Using mail (2.3.3)
Using actionmailer (3.1.0)
Using arel …Run Code Online (Sandbox Code Playgroud)