需要帮助,新手整合 Carrierwave 和 Mongoid 时出错:
NoMethodError (undefined method `validate_integrity' for :ImageUploader:Symbol):
app/models/picture.rb:5:in `<class:Picture>'
app/models/picture.rb:1:in `<top (required)>'
app/controllers/uea_controller.rb:12:in `imageup'
bundle show:
Gems included by the bundle:
* actionmailer (3.2.11)
* actionpack (3.2.11)
* activemodel (3.2.11)
* activerecord (3.2.11)
* activeresource (3.2.11)
* activesupport (3.2.11)
* arel (3.0.2)
* builder (3.0.4)
* bundler (1.2.3)
* carrierwave (0.8.0)
* carrierwave-mongoid (0.6.0)
* coffee-rails (3.2.2)
* coffee-script (2.2.0)
* coffee-script-source (1.6.2)
* erubis (2.7.0)
* execjs (1.4.0)
* hike (1.2.2)
* i18n (0.6.4)
* journey (1.0.4)
* jquery-rails (2.2.1)
* json (1.8.0)
* mail (2.4.4)
* mime-types (1.23)
* mongoid (3.1.4)
* mongoid-grid_fs (1.8.0)
* moped (1.5.0)
* multi_json (1.7.3)
* origin (1.1.0)
* polyglot (0.3.3)
* rack (1.4.5)
* rack-cache (1.2)
* rack-ssl (1.3.3)
* rack-test (0.6.2)
* rails (3.2.11)
* railties (3.2.11)
* rake (10.0.4)
* rdoc (3.12.2)
* rmagick (2.13.2)
* sass (3.2.9)
* sass-rails (3.2.6)
* sprockets (2.2.2)
* thor (0.18.1)
* tilt (1.4.1)
* treetop (1.4.12)
* tzinfo (0.3.37)
* uglifier (2.1.1)
Controller Class:
class UeaController < ApplicationController
respond_to :html, :json
def showimage
end
def imageup
@picture = Picture.new params[:upfile]
if @picture.save
@msg = {:url=>@picture.image.url(:original),:title=>params[:pictitle],:original=>params[:fileName],:state=>'SUCCESS'}
else
@msg = {:url=>'',:title=>'',:original=>'',:state=>'文件保存时出错'}
end
respond_with @msg
#render :json=>msg.to_json
end
def imageManager
end
end
Model Class:
class Picture
include Mongoid::Document
attr_accessible :image
field :image, type: String
mount_uploader :image, :ImageUploader
end
Uploader Class:
class ImageUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end