class PublicOfficialDeclaration < ActiveRecord::Base
  attr_accessible :declaration, :declaration_date, :description, :event, :link,
    :name, :place, :public_official_id

  # Non database attributtes
  attr_accessible :attachment

  validates :public_official_id, presence: true
  validates :declaration, presence: true
  validates :declaration_date, presence: true

  belongs_to :public_official

  # Paperclip
  has_attached_file :attachment

  before_save :set_name
  def set_name
    write_attribute(:name, "#{public_official.name} #{I18n.l(declaration_date, format: :default)}")
  end
end
