Sha256: a3799700529062dcec93f3f0a6f6d35631d88c79a4f8e05a66f7c4bc8b0916ed

Contents?: true

Size: 855 Bytes

Versions: 6

Compression:

Stored size: 855 Bytes

Contents

# баннер в самом верху страницы
module C80NewsTz
  class Banner01 < ActiveRecord::Base
    mount_uploader :image, Bimage01Uploader
    validates_with BannerValidator

    before_save :before_save_format_href

    # выдать рандомный активный баннер
    # если такового нету - вернётся null
    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

    private

    # каждая ссылка должна начинаться с http://
    def before_save_format_href
      str = 'http://'
      if self.href[0..6] != str
        self.href = "#{str}#{self.href}"
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
c80_news_tz-0.1.1.26 app/models/c80_news_tz/banner01.rb
c80_news_tz-0.1.1.25 app/models/c80_news_tz/banner01.rb
c80_news_tz-0.1.1.24 app/models/c80_news_tz/banner01.rb
c80_news_tz-0.1.1.23 app/models/c80_news_tz/banner01.rb
c80_news_tz-0.1.1.22 app/models/c80_news_tz/banner01.rb
c80_news_tz-0.1.1.21 app/models/c80_news_tz/banner01.rb