开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜