2013-10-28 48 views
3

我正試圖用回形針將第二個附件添加到模型中。我使用的是一個簡單的縮略圖處理器:如何在多個附件中使用回形針before_post_process?

has_attached_file :attachment, :styles => { :thumb => "100x100>" } 
has_attached_file :attachment2, :styles => { :thumb => "100x100>" } 

我希望它不會創建非圖像類型,如縮略圖:

before_post_process :is_image? 
def is_image? 
    !(File.extname(attachment_file_name) =~ /\A.jpe?g|pjpeg|gif|x-png|png\Z/i).nil? 
end 

我該怎麼做,對於第二個附件?問題是對attachment_file_name的引用,對於第二個引用將需要attachment2_file_name。

回答

4

看來有可能寫:

before_attachment_post_process :is_image? 
before_attachment2_post_process :is_image2?