Class Document
In: app/models/document.rb
Parent: ActiveRecord::Base

Methods

data   data=   filename=   find   human_size   size  

Public Class methods

We override find to exclude the whole file contents (the ‘data’ column) from our result set. Operation should be almost transparent (see note by self#data=)

Public Instance methods

IMPORTANT THING TO REMEMBER:

Contrary to most Rails conventions, data is saved AS SOON AS IT IS RECEIVED in order to free us a bit from the pain of getting the full file data at every instantiation.

Windows uploads are usually sent with their full path information

  • Strip it, to be on the safe side, and to avoid confusing just

about everybody

How should a human get (and understand) the size? In familiar bytes/KB/MB/GB representations

We avoid needlessly bringing in the full data - so just ask the DB to get its size.

[Validate]