Rails 3.2.3 Carrierwave-Gem Ошибка приватного метода `write_uploader', вызванного

я использую Carrierwave -Gem для загрузки файлов в своем веб-приложении. Но я не могу сохранить изображение из-за следующей ошибки:

private method `write_uploader' called for #<Image:0x000000035eafd0>

Я не нашел хорошо работающее решение для решения этой проблемы. Вот мой код приложения:

/приложение/модели/image.rb

#encoding: utf-8
class Image < ActiveRecord::Base

  scope :public, joins(:gallery).where('images.public=true AND galleries.public=true')

  belongs_to :gallery
  attr_accessible :gallery_id, :name, :image, :remote_image_url, :desc, :public, :crop_x, :crop_y, :crop_w, :crop_h
  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  mount_uploader :image, ImageUploader

  validates :gallery_id, presence: true
  after_update :crop_gallery_image

  # this method is needed and a part of a quickhack because of an bug in caarierwave, if you want to save files in a private folder
  def image_url(image_size)
    Rails.application.routes.url_helpers.image_url(image_id: self.id, image_size:     image_size, host: (Rails.env.production? ? 'xyz.de': 'localhost:3000'))
  end

  def crop_gallery_image
    image.recreate_versions! if crop_x.present?
  end  

end

/app/uploaders/image_uploader.rb

#encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick

  storage :file

  #the following methods doesn't work @ the moment; i used an initializer to change the paths
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def cache_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end


  version :thumb do
    resize_to_limit(200, 200) 
  end

  version :medium do
    resize_to_limit(800, 600)  
  end

  version :normal do
    resize_to_limit(1024, 768)
  end

  version :big do
    resize_to_limit(1440, 1024)  
  end

  version :gallery do
    process :crop
    resize_to_fill(920, 400)
  end

  def crop
    if model.crop_x.present?
      resize_to_limit(1024, 768)
      manipulate! do |img|
        x = model.crop_x.to_i
        y = model.crop_y.to_i
        w = model.crop_w.to_i
        h = model.crop_h.to_i
        img.crop!(x, y, w, h)
      end
    end
  end
end

Исключение вызывается после того, как я пытаюсь загрузить изображение. Я использую Ruby 1.9.3-p125, Rails 3.2.3 и настоящий Carrierwave-Gem (мастер-ветвь)


person c-c    schedule 19.05.2012    source источник


Ответы (1)


я нашел решение. Сначала я должен позвонить "mount_uploader :image, ImageUploader" @ !!!!

person c-c    schedule 01.06.2012