Class: C80NewsTz::Banner03

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/c80_news_tz/banner03.rb

Class Method Summary collapse

Class Method Details

.count_activeObject

выдать количество активных баннеров



24
25
26
# File 'app/models/c80_news_tz/banner03.rb', line 24

def self.count_active
  self.where(:is_active => true).count
end

.random_activeObject

выдать рандомный активный баннер если такового нету - вернётся null



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/c80_news_tz/banner03.rb', line 11

def self.random_active
  result = nil
  a = self.where(:is_active => true)
  if a.count > 0
    b = a.offset(rand(a.count)).first
    if b.image.present?
      result = b
    end
  end
  result
end