2011-08-30 57 views
0

我需要帮助来设置与vestal_versions的回形针。我跟着这个教程回形针+ vestal_versions问题

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

但是当我尝试上传文件,我得到这个错误

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

NoMethodError(未定义的方法'版本”为#):

我的文件模型是从建筑和建筑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

您需要添加(版本)到您的模型

class BuildingPdf < ActiveRecord::Base 
    versioned 

    .. 

end 
+0

嗯感谢,但认为再​​给我一次错误[回形针]保存附件。 完成在1512ms Mysql2 ::错误500内部服务器错误(表 'db.versions' 不存在): 应用程序/模型/ building_pdf.rb:10:'版本” 配置/初始化/ versioning_with_paperclip.rb :5:在'保存'中应该包含哪些表格版本?我还必须在它上面做一个轨道回形针? – neimad

+0

您需要在 之前运行耙子迁移$ rails生成vestal_versions:迁移 $ rake db:migrate – DevDude

+0

太棒了!谢谢。使用版本日期访问当前和以前版本,我需要使用@ buildingpdf.versions或类似的东西?与:当前或:以前?如何使用此版本进行导航?再次感谢! – neimad