Forum: Ruby on Rails Model with file uploads

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John (Guest)
on 2006-04-13 17:55
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
This topic is locked and can not be replied to.