1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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

  # paperclip
  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