class Asset < ActiveRecord::Base
attr_accessor :avatar
attr_accessible :description, :work_id, :private, :avatar, :update_id, :user_id, :item
belongs_to :user
belongs_to :work
belongs_to :update
validates_presence_of :work_id
validates_presence_of :user_id
has_attached_file :item, :styles => { :large => ["x600"], :medium => ["300x", :png], :thumb => ["x70", :png] }
before_post_process :image?
validates_attachment_presence :item
validates_attachment_content_type :item, :content_type => [/(image)/,/(mp3)/,/(doc)/,/(rtf)/,/(text)/,/(txt)/,/(html)/,/(zip)/,/(rar)/,/(pdf)/]
default_scope order('updated_at DESC')
scope :public, where("private <> ?", true)
scope :photos, where("item_content_type LIKE ?", "image%")
scope :resources, where("item_content_type NOT LIKE ?", "image%")
end
class Update < ActiveRecord::Base
belongs_to :work
belongs_to :user
belongs_to :language
has_many :assets
has_many :resources
has_many :photos
validates_presence_of :work_id
validates_presence_of :user_id
validates_presence_of :content
validates_presence_of :period, :if => Proc.new { |update| update.report }
scope :work, lambda { |work| where(:work_id => work) }
scope :non_private, where("private = ? or private is NULL", false)
scope :recent, order('updated_at DESC')
default_scope :order => 'updated_at DESC'
end