# Model with file uploads

**URL:** <https://www.ruby-forum.com/t/model-with-file-uploads/57735>\
**Category:** Rails\
**Created:** [April 13, 2006, 3:55pm UTC](https://www.ruby-forum.com/t/model-with-file-uploads/57735 "2006-04-13T15:55:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [April 13, 2006, 3:55pm UTC](https://www.ruby-forum.com/t/model-with-file-uploads/57735/1 "2006-04-13T15:55:07Z")

</div>

I’m working on a model for a videos table that include the video info  
(title, description) and a couple of uploads (video file, thumb image)  
I was going to use the file\_column plugin but I dont like the idea of  
storing the file names in the database when I dont need to, plus I dont  
think it is very flexible.

Here’s what I done. What do you think of this? Any suggestions?

class Video \< ActiveRecord::Base  
acts\_as\_taggable

attr\_accessor :field\_tags  
attr\_accessor :field\_thumb  
attr\_accessor :field\_video

validates\_presence\_of :title  
validates\_presence\_of :description  
validates\_presence\_of :field\_tags

def validate\_on\_create  
errors.add ‘field\_thumb’, ‘Invalid thumb’ unless  
!self.field\_thumb.read.empty?  
errors.add ‘field\_video’, ‘Invalid video’ unless  
!self.field\_video.read.empty?  
end

def after\_create  
self.tag\_with self.all\_tags

```
# upload field_video and upload field_thumb

```

end

def after\_update  
self.tag\_with self.all\_tags  
end

def after\_delete  
# delete video and thumb files  
end

def tags  
# return formatted tags from tag\_list  
end

def thumb  
# return full thumb url  
end

def video  
# return full video url  
end  
end
