gpt4 book ai didi

ruby-on-rails - Rails 3 - 带版本控制的图像回形针 - 可能吗?

转载 作者:行者123 更新时间:2023-12-01 16:12:57 25 4
gpt4 key购买 nike

我希望听到您关于使用回形针进行图像版本控制的建议。

有人知道任何优雅的 paper_clip 图像、版本控制实现解决方案吗?

用例,用户上传图像。然后,用户上传图像以替换之前的更新。用户可以看到图像的踪迹。

谢谢

最佳答案

我会做这样的事情

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

在成功创建新附件记录后,在处理图像上传的 Controller 中,将现有的 User#current_attachment 替换为新创建的 User#current_attachment。

如果您想要版本号,您可以为用户拥有的附件添加 counter_cache,并在附件的 before_create 回调中使用它的值。

关于ruby-on-rails - Rails 3 - 带版本控制的图像回形针 - 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4072846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com