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
|
# File 'lib/subj_models/user_video.rb', line 5
def self.included(including_class)
including_class.class_eval do
belongs_to :owner, class_name: 'User', foreign_key: :user_id
belongs_to :brand
has_and_belongs_to_many :user_specializations
has_many :likes, dependent: :destroy
has_many :liked_users, -> { uniq }, through: :likes, source: :user
validates_presence_of :title
validates_presence_of :brand
validates_presence_of :owner
has_attached_file :video_snapshot, default_url: '/images/default_video_snapshot.png', styles: { thumb: '300x300>' }
validates_attachment_content_type :video_snapshot, content_type: /\Aimage\/.*\z/
validates_attachment_size :video_snapshot, less_than: 10.megabytes
has_attached_file :full_video, default_url: ''
validates_attachment_content_type :full_video, content_type: /\Avideo\/.*\Z/
validates_attachment_size :full_video, less_than: 300.megabytes
has_attached_file :short_video, default_url: ''
validates_attachment_content_type :short_video, content_type: /\Avideo\/.*\Z/
validates_attachment_size :short_video, less_than: 100.megabytes
before_full_video_post_process :rename_full_video
before_short_video_post_process :rename_short_video
before_video_snapshot_post_process :rename_video_snapshot
end
end
|