overriding ActiveRecord.save to read in property before save
I have this in my object's save
class Uploa开发者_高级运维dFile < ActiveRecord::Base
def save
dir = 'public/data'
path = File.join(dir, 'nfile')
from = contents.path
contents = `cat #{from}`
super
end
end
contents stores a file object from a multi-part form submit.
This is very quick and dirty (yes I know cat #{from}
is probably not a good idea). Why is it that after super is called contents is # and not the contents of the file?
Thanks.
Use the before_save callback http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
精彩评论