Class: C80NewsTz::Banner01

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

Class Method Summary collapse

Class Method Details

.random_activeObject

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



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/c80_news_tz/banner01.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