views:

65

answers:

4

I need to add the ability to upload and store any kind of file, PDF, XLS, DOC, etc. What is the best way to do this in a ruby on rails application?

+4  A: 

I'd recommend you to use paperclip or carrierwave both are really good libs and work out of the box in most cases.

Francisco
+4  A: 

I think this is exactly what you're looking for.

Upload files.

Shreyas Satish
A: 

you can also look at attachment_fu rails.

Anubhaw
I personally wouldn't recommend attachment_fu as it appears to be unmaintained, and has been so for over a year.
luke_randall
A: 

I've worked with two of the big players when it comes to file uploads. carrierwave and paperclip.

They provide a good solution for a common task with support for different storage alternatives. Both support filesystem and S3. Carrierwave also supports Rackspace Cloud Files and MongoDB’s GridFS.

I would recommend carrierwave because of one aspect where they are different to use. It uses a separate upload class that you mount on your model. This separates your code related to the file upload from the model code. I find this approach cleaner and easier to test.

nibbo
WRT storing info in the object's atts, you can do this in Paperclip by defining a separate model for your uploaded object e.g. Create a profile object that has_one Image, using the image class to store the upload atts.
Mr. Matt
I now realize that I thought one thing and wrote another. What I wanted to express was that I feel that having the code in a separate upload class, and just one attribute added to the model, is a cleaner implementation than having four attributes and post processing code in the model.You will still have to wrap both solutions in a separate model if you want to include it in a one/many to many relationship.
nibbo
Answer is now edited according to comments.
nibbo