2010-11-01 46 views

回答

0

我會做這樣的事情

class Attachment < ActiveRecord::Base 
    belongs_to :user 
    has_attached_file :image 
end 

class User < ActiveRecord::Base 
    belongs_to :current_attachment, class_name: 'Attachment' 
    has_many :attachments, order: 'attachments.created_at ASC' 
end 

和正在處理的圖片上傳成功創建新的附件記錄之後控制器,取代現有的用戶#current_attachment新創建的一個。

如果您想要一個版本號,您可以爲用戶附件添加一個counter_cache,並在附件上的before_create回調函數上使用它的值。