我正在尝试在我的第一个 rails 应用程序中实现 Paperclip,而我碰巧将 rails 3 和 mongodb 与 mongomapper 一起使用。
我按照本指南了解如何让所有东西一起工作
正如博客文章所建议的那样,我已经将回形针放入 config/initializers 目录,我安装了 gem,gem 在 gemfile 中(rails 3 对),我运行了捆绑器。
在我的用户类中,我添加了
需要“回形针”
当我加载应用程序时,我收到以下错误,
用户:类的未定义方法“has_attached_file”
回形针文件看起来像这样
模块回形针
模块类方法
def has_attached_file name, options = {}
包括 InstanceMethods
write_inheritable_attribute(:attachment_definitions, {}) 如果 attachment_definitions.nil?
attachment_definitions[name] = {:validations => []}.merge(options)
after_save :save_attached_files
before_destroy :destroy_attached_files
定义回调:before_post_process,:after_post_process
define_callbacks :"before_#{name}_post_process", :"after_#{name}_post_process"
定义方法名 |*args|
a = attachment_for(名称)
(args.length > 0) ? a.to_s(args.first) :一个
结尾
define_method "#{name}=" 做 |file|
attachment_for(name).assign(file)
结尾
定义方法“#{name}?” 做
attachment_for(name).file?
结尾
validates_each 名称,:logic => lambda {
附件 = attachment_for(名称)
attachment.send(:flush_errors) 除非 attachment.valid?
}
结尾
结尾
模块插值
# 处理字符串 id (mongo)
def id_partition 附件,样式
if (id = attachment.instance.id).is_a?(Integer)
("%09d" % id).scan(/\d{3}/).join("/")
别的
id.scan(/.{3}/).first(3).join("/")
结尾
结尾
结尾
结尾
关于我可能做错了什么的任何建议?我的步骤正确吗?