Storing documents using Ruby On Rails - ruby-on-rails

I would like users of my ruby on rails app to be able to upload documents (Word Documents, Spreadsheets, PDFs, etc). What is the best way of doing this?

I've used file_column, attachment_fu, and paperclip. I've also had to dive into the source on all three plugins.
Without a doubt, I recommend paperclip above the others. The source is easier to read and understand. Its easier to extend. It doesn't do extraneous file copies.
Go with paperclip and let us know if you have any questions.

"Best" depends on your exact needs, but have a look at PaperClip. It's a pretty easy way to integrate files with ActiveRecord.

I agree that Paperclip is the best solution currently available.
If you decide to use Paperclip, you might want to take a look at this question which discusses how to display thumbnails for non-image types (.doc, .xls etc).
Set path for original images using paperclip in Rails?

Related

How to implement a rich text document store in Rails

I need a tiny (less than 100 total) document store in a Rails 3.2 app where a user can create, edit, save, and delete rich text documents (ideally including images and other attached items). There is no file system available. Everthing must go in PostgreSQL database tables. The documents will serve as system-wide email and message banner templates.
My approach has been CKEditor. But the ckeditor gem seems wired for attachments as files. Also, it does not provide create/update storage of the document itself, just attachments.
I know how to roll my own model/controller/view the CKEditor but surely there's a simpler way.
So what is the most direct way to my goal of the rich text document store? Is there a plugin or gem?
More CKEditor references: This thread makes it look like a major project, but it's 2 years old. This one makes it sound like the default, but no other document does.
More
Using S3, Dropbox as suggested are also nogo. As I said, data must reside in PgSQL tables. Good news: found the paperclip_database gem. Bad news: doesn't work seamlessly with the ckeditor gem. The main issue boils out to this bit in the source file database.rb:
def setup_paperclip_files_model
#TODO: This fails when your model is in a namespace.
Indeed it does, as in the Ckeditor::Asset model! Trying a monkey patch now. If anyone has already made these three gems work together correctly, I'll give you the bounty for a pointer!
Pretty sure CKEditor makes it fairly simple to edit database form fields, which is all you'd need for editing the document itself, correct?
As far as attachment storage, you can use paperclip to manage the attachments -- file storage is just the default. If you use paperclip, you can then use one of many storage options from there, such as Amazon S3 storage, Dropbox, or create your own.
Hope that helps.
The first thread you linked to has it correctly: you need to (find or) write a custom server connector, and configure CKEditor to use it. You can find the relevant updated docs here:
http://docs.ckeditor.com/#!/guide/dev_file_browser_api

File upload Rails Custom

I am wondering how can i upload my file. I am have read this http://guides.rubyonrails.org/form_helpers.html#uploading-files but not to sure how to read and write the data from the controller? I also read this http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm but placing them both together confused me. I don't like gem has i don't understand where the coded is stored, and doesn't allow flexibility in term of me able to write code specific to my application. Any help is appreciated
I would suggest using the Paperclip gem. The documentation is very straight forward and explains each of the steps in the file upload process.

What is the simplest Rails file upload method?

I've looked at the available options and it seems like everything is optimized for image uploading as display. I just need simple file upload and retrieval. Are there any good options?
Paperclip is a popular choice for uploading and sizing images, but you can upload any type of file with it (doc, zip, txt, pdf... anything). Highly recommended. https://github.com/thoughtbot/paperclip
I like carrierwave. It has built in support for s3, has no workaround for setting up apps on heeroku unlike paperclip.
I use Carrierwave for mine and have been happy with it. I am just uploading general files, not specifically images. It is easy to implement and has good advanced features if you need them later. It also integrates with Fog to make using remote storage sources (like s3 or rackspace cloud files) easy.
Carrierwave benefits:
With carrierwave, the attachment is a seperate model instead of an attribute on an existing model, which might make things cleaner to work with.
It comes with the ability to attach a file via url (user passes in a url to a file) instead of uploading with a form).
It comes with some sort of way to remember files across form validation failures, although I've never used this and I'm not sure how it's done... maybe with two forms and ajax?
It seems to have a more engaged and enthusiastic community around it, with more projects extending it.
For S3, they use fog instead of aws-s3, and fog has much more active development.
That said, paperclip is pretty great and is actively maintained, and might come with handier default image manipulation stuff, I'm not sure.

How do I add file uploads to a rails app?

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?
I think this is exactly what you're looking for.
Upload files.
I'd recommend you to use paperclip or carrierwave both are really good libs and work out of the box in most cases.
you can also look at attachment_fu rails.
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.

mongodb gridfs carrierwave or joint or other?

i want to store all my assets in mongo gridfs. i was trying to get
carrierwave setup with mongomapper and gridfs but seems carrierwave
supports mongoid now instead.
I need to be able to save different size versions / cropped versions
of an image so thats why i was going to use carrierwave. Currently
its set up to store on file system using paperclip but paperclip is
not easy or i have not found a good way to store in gridfs. ??
Should i be using joint to store assts ? but then how do i create
versions etc ?
I basically have muliple models that can have many assets. My models
are mongomapper documents / embedded docs, so i could use mongoid for
my assets model and use carrierwave ....?
please can any one help with the best solution to this ? and
hopefully point me to good examples!
thanks alot
rick
I recommend joint and just storing originals. From there, you can create alternate versions on the fly. I have used http://github.com/quirkey/imanip on projects to create alternate sizes. On the first request I typically cache the original to the file system for speedier requests and then create/cache the requested version/size.
I recommend carrierwave, because if you decide, for whatever reason, to change file stores (for example, if you want to move to a filesystem-based store instead), it will be much easier with carrierwave.
There is a carrierwave plugin called mm-carrierwave that lets you use carrierwave with MongoMapper.

Resources