简体   繁体   English

带有生成/下载/上传和状态的Rails文件存储

[英]Rails file storage with generate/download/upload and state

My web platform helps our association manage projects. 我的网络平台可帮助我们的协会管理项目。 Many documents are auto-generated by the platform, then our members are expected to generate them, and eventually download-check-reupload them. 该平台会自动生成许多文档,然后我们的成员将生成它们,并最终下载-检查-重新上传它们。 We also need to keep track of different information like date of signature, of reading, etc. 我们还需要跟踪不同的信息,例如签名日期,阅读日期等。

Currently, a base class is used to represent such documents, which is then inherited to define every document type we use (for example documents are auto-generatable or not, can be uploaded, etc.). 当前,基类用于表示此类文档,然后继承该基类以定义我们使用的每种文档类型(例如,文档是否可以自动生成,可以上载等)。 The files need to be store outside the rails app folder. 这些文件需要存储在rails app文件夹之外。 The complete filename/path/generation is defined in every inherited class 在每个继承的类中都定义了完整的文件名/路径/生成

Is there an easy way to achieve this with paperclip/carrierwave ? 有回形针/载波实现这一目标的简便方法吗? Or should I rather implement this myself (eventually drawing some inspiration from the source code of aforementionned gems ?) 还是我应该自己实现(最终从上述宝石的源代码中得到一些启发?)

I'm afraid these gems may be too limited for what I want to do. 恐怕这些宝石对于我想做的事情可能太有限了。 For example : when autogenerating the file, eventually the existing file will be overwritten, is this likely to mess up with paperclip/carrierwave ? 例如:当自动生成文件时,最终现有文件将被覆盖,这是否可能与回形针/载波混在一起? Or do I need to do extra things to make it work as intended ? 还是我需要做一些额外的事情才能使其按预期工作?

Note : I am using rails 4.1 with mongoid. 注意:我正在将rails 4.1与mongoid一起使用。

So I decided to use Carrierwave. 因此,我决定使用Carrierwave。 As I expected, it was not enough to just generate files using other gems, because then they weren't recognised. 正如我预期的那样,仅使用其他gem生成文件是不够的,因为这样就无法识别它们。

So in my controller, after the file is generated, I must explicitely tell carrierwave to overwrite the same file at the same place : 因此,在我的控制器中,在生成文件之后,我必须明确地告诉载波在相同位置覆盖相同文件:

def generate_document
    if @doc.generate_document # Generate the file and store it
        flash.notice = "Sir yes sir ! #{t(@doc.human_name)} successfully generated !"

        # Must do this because otherwise file isn't recognised by carrierwave :
        @doc.document_file = File.open(@doc.full_path)

        @doc.save!
    else
        flash.alert = "Krap, it failed..."
    end
    redirect_to ...
end

Where document_file is mount_uploader :document_file, DocumentFileUploader of my document class 其中document_file是mount_uploader :document_file, DocumentFileUploader我的文档类的mount_uploader :document_file, DocumentFileUploader

Unless someone provides a better answer, I'll select mine. 除非有人提供更好的答案,否则我将选择我的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM