2010-11-01 47 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回调函数上使用它的值。