2011-08-30 56 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