an advice to manage pdf documents.

I have a model say, Company, that have many document.
A Document belongs_to Company.
Documents are all pdf files so I have to upload them and I think to
save them in the filesystem.
How you manage document names?
Do you create a folder for every company in which save their documents
or rename documen name to avoid duplicates or to avoid rewrites?

I have a polymorphic AttachingType model, which has a FileAttachment
model associated to it. The file attachment stores info about the file
size, mime type, original name, etc, and I renamed the file to be the
id of the file_attachment object (and the original file extension) and
save it to a local folder.
If I think I'm going to have *lots* of files in the folder (in the
order of tens of thousands), I break the structure down and put all
ids beginning with 1 in one sub-folder, 2 goes in another, etc.

In my models I create a AttachingTypePhoto (for instance) association
and all the rest "just works".

I should *really* polish-up the code and stick it in the public domain :-/

Do you use paperclip?

erm.. no :slight_smile:

I use a model of my own. Paperclip is great for bunging in a single
file attachment (inline, into your model), but wasn't a very
flexible/scalable solution (or at least it wasn't when I needed to do
file attachments a few years ago).

By having my own model I can treat files like any other association;
and attach one, many, or have different types depend on my needs.

I have Company has_many :documents
and
Document belongs_to :company

Document has various attributes and the pdf file associated.
I still don't understand if paperclip is suitable for my needs in this case.

That I can't say. Only you can answer whether it is suitable for your
case. Sounds
like it probably wouldn't be the end of the world to use paperclip;
but that's certainly not what you asked at the start of the thread -
you were asking about how to manage document names.
If you're planning on using paperclip, doesn't that handle the file
naming for you?

PS The biggest issues I had with paperclip was the unnormalised
approach of adding four fields to your model for each file you want to
attach, and that it doesn't (didn't?) allow multiple file attachments.

I've just had a goggle, and it appears that I wasn't the only one, and
this blog:
http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html
...describes a similar solution to what I arrived at.

Do you use paperclip?

PS The biggest issues I had with paperclip was the unnormalised
approach of adding four fields to your model for each file you want to
attach, and that it doesn't (didn't?) allow multiple file attachments.

I've just had a goggle, and it appears that I wasn't the only one, and
this blog:
http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html
...describes a similar solution to what I arrived at.

Thank you for your answers.

s/unnormalised/demormalised/

However my doubt is like your how to manage multiple file attachments.
In my case Company has many pdf documents.
Rather than attach the pdf files directly to Company I've created a
Document model.
Now, Company has_many documents and every document has a pdf file as attachemnt.
Do you think this is a valid approach?

Like I said, that's exactly what I do, so I guess I must think it's valid :slight_smile:

You can always set up a "has_many :through" for your Company's files
if you *need* to call "company.files" rather than working though the
"company.documents" collection.