重命名具有多个回形针附件的 Rails 模型中的文件

发布于 2024-11-07 13:36:48 字数 478 浏览 0 评论 0原文

我有一个 Rails 模型,有 4 种回形针附件类型(top_graphic、intro_graphic、bg_audio 和缩略图),每种类型都需要在上传时根据不同的逻辑重命名其文件。我如何检查后处理器中当前正在更新 4 个附件中的哪一个,以便执行此操作?

before_post_process :file_rename

def file_rename
  # e.g., if top_graphic file is being uploaded, rename file to "top_graphic.jpg"
  # e.g., if intro_graphic file is being uploaded, rename file to "intro_graphic.jpg"
end

** 请注意,我确实知道我可以为每种附件类型创建 4 个新模型并以这种方式附加它们。我希望避免这样做,因为这似乎是不必要的文件系统和数据库混乱。

谢谢。

I have a Rails model that has 4 Paperclip attachment types (top_graphic, intro_graphic, bg_audio, and thumbnail), each of which needs to have its file renamed according to different logic upon upload. How can I check which of the 4 attachments is currently being updated in the post-processor in order to do so?

before_post_process :file_rename

def file_rename
  # e.g., if top_graphic file is being uploaded, rename file to "top_graphic.jpg"
  # e.g., if intro_graphic file is being uploaded, rename file to "intro_graphic.jpg"
end

** Please note that I do know that I could create 4 new models for each of the attachment types and attach them that way. I wish to avoid doing this as it seems like unnecessary filesystem and database clutter.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文