views:

53

answers:

2

I would like to know what will be the best way to save binary files 'in database'. Of course they will be on the disk as files, but i need some 'link' to them in the DB. Any great solutions?

+1  A: 

If you don't have anything against mongodb and gridfs, there's an example here http://socialmemorycomplex.net/2010/06/02/gridfs-with-mongoid-and-carrierwave-on-rails-3/

hellvinz
+4  A: 

Use Paperclip to attach a file to a model.

Say you have a mortgage that has a document

class Mortgage < ActiveRecord::Base
  has_attached_file :document
end

Later:

mortgage = Mortgage.find(params[:id])
document = mortgage.document

Paperclip is usually used with images, but works with all types of files. You can easily store on s3 as well.

Jesse Wolgamott
Yes, Paperclip seems to be a very accepted way to do this.
smoove666