重命名具有多个回形针附件的 Rails 模型中的文件
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论