Sha256: 97d6275b9f682c1df1ae6173cc227593bc7437a72ae42cc80c29ee9045ea8c2c

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

class Video

  include Mongoid::Document
  include Mongoid::Timestamps

  PER_PAGE = 6

  field :name, :type => String
  field :descr, :type => String

  default_scope ->{ where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc }) }

  field :is_trash, :type => Boolean, :default => false
  field :is_public, :type => Boolean, :default => true
  field :is_feature, :type => Boolean, :default => false

  field :x, :type => Float
  field :y, :type => Float

  field :lang, :type => String, :default => 'en'

  field :youtube_id, :type => String
  validates :youtube_id, :uniqueness => true, :presence => true

  belongs_to :tag
  belongs_to :city
  belongs_to :site
  validates :site, :presence => true
  belongs_to :user
  validates :user, :presence => true
  
  accepts_nested_attributes_for :site, :tag, :city


  def self.list
    [['', nil]] + Video.all.order_by( :name => :desc ).map { |item| [ item.name, item.id ] }
  end

  set_callback( :create, :before ) do |doc|
    if doc.is_public
      doc.city.add_newsitem( doc ) unless doc.city.blank?
      doc.site.add_newsitem( doc ) unless doc.site.blank?
    end
    
  end

end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
ish_models-0.0.6 lib/video.rb
ish_models-0.0.3 lib/video.rb
ish_lib-0.0.8 app/models/video.rb
ish_lib_engine-0.0.5 app/models/video.rb
ish_lib_engine-0.0.3 app/models/video.rb
ish_lib_engine-0.0.2 app/models/video.rb
ish_lib_engine-0.0.1 app/models/video.rb
ish_lib-0.0.6 lib/app/models/video.rb
ish_lib-0.0.3 app/models/video.rb