2012-07-23 15:25:37 +01:00
|
|
|
require 'digest/md5'
|
|
|
|
|
|
|
|
class FlashNotify < ActiveRecord::Base
|
|
|
|
# attr_accessible :title, :body
|
|
|
|
|
|
|
|
STATUSES = %w[error success info]
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
validates :status, inclusion: {in: STATUSES}
|
|
|
|
validates :body_ru, :body_en, :status, presence: true
|
2012-07-23 15:25:37 +01:00
|
|
|
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :published, -> { where(published: true) }
|
2012-07-23 15:25:37 +01:00
|
|
|
|
2014-03-19 22:40:47 +00:00
|
|
|
attr_accessible :body_ru, :body_en, :status, :published
|
|
|
|
|
2012-07-23 15:25:37 +01:00
|
|
|
def hash_id
|
|
|
|
@digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def body(language)
|
|
|
|
read_attribute("body_#{language}")
|
|
|
|
end
|
|
|
|
|
2012-07-25 13:41:06 +01:00
|
|
|
def should_show?(cookie_hash_id)
|
|
|
|
cookie_hash_id != hash_id && published
|
2012-07-23 15:25:37 +01:00
|
|
|
end
|
2014-06-03 10:21:13 +01:00
|
|
|
|
|
|
|
def alert_class
|
|
|
|
"alert-#{status == 'error' ? 'danger' : status}"
|
|
|
|
end
|
2012-07-23 15:25:37 +01:00
|
|
|
end
|