在网上爬点图片,需要使用 carrierwave 和 active_record,但是总是提示 cartoon_pic.rb:4:in <class:CartoonPic>: uninitialized constant CartoonPic::PictureUploader (NameError)
向社区求助。有没有相关的文档,希望大家指路
spider.rb
require 'rubygems'
require 'active_record'
require 'carrierwave'
require 'carrierwave/mount'
load '/home/xxxx/xxx/spider/database_init.rb'
database_init.rb
database_file = File.join('/home/xxx/xxx/spider','database.yml')
database_obj = YAML.load_file(database_file)
ActiveRecord::Base.establish_connection(database_obj['production'])
load '/home/xxx/xxxx/spider/uploaders/picture_uploader.rb'
load '/home/xxxx/xxx/spider/cartoon_pic.rb'
puts CartoonPic.last.picture
cartoon_pic.rb
class CartoonPic < ActiveRecord::Base
attr_accessible :picture, :page, :episode
mount_uploader :picture, PictureUploader
belongs_to :cartoon_work
end
当我执行 ruby spider.rb
时,就会提示 我cartoon_pic.rb:4:in <class:CartoonPic>: uninitialized constant CartoonPic::PictureUploader (NameError)
在 wiki 中有一篇介绍使用 Padrino 使用 carrierwave 的介绍,
地址 https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Make-CarrierWave-work-with-Padrino
可能 activerecord 有问题,所以推荐使用 require 'carrierwave/orm/activerecord'
错误也就解决了。
但是出现了新的错误
ruby/gems/2.0.0/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:43:in `join': string contains null byte (ArgumentError)