gpt4 book ai didi

ruby-on-rails - rails : Paperclip question regarding column names

转载 作者:行者123 更新时间:2023-12-01 13:04:08 26 4
gpt4 key购买 nike

我有两种使用 Paperclip 的场景,但我不确定如何调整设置,或者是否可能甚至有必要。在这方面需要更多经验丰富的专业人士的建议。

首先,我有一个用于上传的文档模型,例如 PDF,它被定义为:

has_attached_file :document...

这会给我列名,例如 @document.document_file_name。不管怎样,我可以用 @document.file_name 代替吗?

其次,我有 Gallery.rb,里面有很多 Picture.rb。这里也有同样的情况。我可以避免使用@picture.picture_file_name 吗?或者这是否真的应该被 Paperclip 提供的 yield 所忽视。

在此先感谢您的任何意见。

最佳答案

我对此的看法:实际文档(PDF 文件)与文档记录(包括物理文档和元数据)不同。因此,将 Paperclip 附件视为模型的属性并在属性之后调用其方法而不是对模型记录本身进行操作是有意义的。

我的一个应用程序也有一个带有附件的 Document 模型,我只是将属性称为 attachment

如果这给您带来太多不便,您可以随时在模型中实现自己的 getter:

class Document < ActiveRecord::Base
has_attached_file :attachment # ... or whatever you are calling it

def file_name
self.attachment.file_name
end

def file_size
self.attachment.file_size
end

def file_type
self.attachment.file_type
end
end

关于ruby-on-rails - rails : Paperclip question regarding column names,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4116092/

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