paperclip + vestal_versions问题

时间:2011-08-30 15:16:31

标签: ruby-on-rails ruby-on-rails-3 paperclip

我需要帮助设置带有vestal_versions的回形针。我按照本教程

http://blog.dmfranc.com/post/1036667709/paperclip-and-vestal-versions

但是当我尝试上传文件时,我收到此错误

[paperclip]保存附件。 在626ms完成500内部服务器错误

NoMethodError(#的未定义方法`version'):

我的文件模型是来自建筑物和建筑物has_menu building_pdf的belongs_to。

class BuildingPdf < ActiveRecord::Base
  belongs_to :building

  has_attached_file :pdf, :keep_old_files => true, :url => "/pdf/:id/versions/:version/:basename.:extension",
  :path => ":rails_root/system/pdf/:id/:version/:basename.:extension"

 Paperclip.interpolates :version do |attachment, style|
   attachment.instance.version.to_s
 end

end

这是我的/lib/initializers/versioning_with_paperclip.rb

module Paperclip
  class Attachment
    def save
      flush_deletes unless @options[:keep_old_files]
      flush_writes
      @dirty = false
      true
    end
  end
end

我还缺少什么?

感谢。

PS。在我的模型中添加版本后,我收到此错误

[paperclip] Saving attachments.
Completed 500 Internal Server Error in 1512ms

Mysql2::Error (Table 'db.versions' doesn't exist):
  app/models/building_pdf.rb:10:in `version'
  config/initializers/versioning_with_paperclip.rb:5:in `save'

1 个答案:

答案 0 :(得分:1)

您需要在模型中添加(版本化)

class BuildingPdf < ActiveRecord::Base
    versioned

    ..

end