3
爲了幹掉附件圖片的代碼,我創建了一個初始化程序來覆蓋Paperclip使用的@default_options
變量。Rails回形針,DRY配置
這樣,我不必一次又一次指定我想要的url,路徑和存儲。
我想走得更遠一步,包括在它的驗證,但我不能讓它工作...
任何想法?
編輯1:我想至少驗證存在和大小。
編輯2:我目前的代碼
module Paperclip
class Attachment
def self.default_options
if Rails.env != "production"
@default_options = {
:url => "/assets/:class/:attachment/:id/:style/:normalized_name",
:path => ":rails_root/public/assets/:class/:attachment/:id/:style/:normalized_name",
:default_style => :original,
:storage => :filesystem,
:whiny => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
}
else
...
end
end
end
normalized_name
部分是外來的功能,壯舉:http://blog.wyeworks.com/2009/7/13/paperclip-file-rename
編輯3:
此博客:http://omgsean.com/2009/02/overriding-paperclip-defaults-for-your-entire-rails-app/ presnents的default_options
哈希與validations
鍵。
所以它可能是可能的,但還沒有找到。
可能想要顯示您擁有的內容以及嘗試過的內容 – Jimmy 2011-01-24 19:12:51
這裏您可以查看示例:) – apneadiving 2011-01-24 19:23:16