我有两个共享多个模型的应用。我创建了一个包含这些模型的gem。减去载波功能和设计方法,它工作得很好(将它们评论出去测试)。但是,当我将它们添加回来时,我会收到错误:
未定义的方法mount_uploader
未定义的方法设计
通过将其放置在其中一个模型的顶部,我能够使载波部分工作,
require "carrierwave"
require "carrierwave/orm/activerecord"
它将允许文件上传,但它不会将其保存在uploads文件夹中,只是在临时文件夹中,它会将tmp哈希值放在数据库中。
这是我的gemspec- journalbooks_core.gemspec
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'journalbooks_core/version'
Gem::Specification.new do |spec|
spec.name = "journalbooks_core"
spec.version = JournalbooksCore::VERSION
spec.authors = [NAME]
spec.email = [EMAIL]
spec.description = "Contains the shared models of journalbooks.com and creative-queue.com"
spec.summary = ""
spec.homepage = ""
spec.license = "MIT"
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_dependency "carrierwave", "= 0.9.0"
spec.add_dependency "devise"
end
这是最初运行的journalbooks_core.rb
require "journalbooks_core/version"
module JournalbooksCore
require "models/virtual_request"
require "models/creative_user"
require "models/user"
require "models/virtual"
require "models/cov_order"
end
这是我一直试图开始工作的模型
class CreativeUser < ActiveRecord::Base
require "uploaders/avatar_uploader"
require "carrierwave"
require "carrierwave/orm/activerecord"
...
mount_uploader :avatar, AvatarUploader
...
end