Sha256: cd573a250d3aa774bb1ff64a1344ef4a6634d28db2fb7ed9a8cd8c4035870ece

Contents?: true

Size: 950 Bytes

Versions: 3

Compression:

Stored size: 950 Bytes

Contents

class Almanac::Blog < ActiveRecord::Base
  belongs_to :author, :class_name => Almanac.user_class

  attr_accessible :title, :description, :author_id, :logo, :background, :retained_logo,
                  :retained_background, :google_analytics, :twitter, :background_tile,
                  :background_blur, :footer, :disqus_shortname

  image_accessor :logo do
    after_assign{|a| a.process!(:thumb, '100x100#').encode(:png) }
  end
  image_accessor :background do
    after_assign{|a| a.process!(:thumb, '1200x>').encode(:png) }
  end

  before_save :author=
  before_create :check_for_uniqueness

  validates_presence_of :author_id
  validates_presence_of :title
  validates_inclusion_of :background_blur, :in => [0, 1, 2]

  def author=
    @author = Almanac.user_class.constantize.find(self.author_id)
  end

  private
  def check_for_uniqueness
    unless Almanac::Blog.first == nil
      raise "You can only have one blog."
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
almanac-0.9.2 app/models/almanac/blog.rb
almanac-0.9.1 app/models/almanac/blog.rb
almanac-0.9.0 app/models/almanac/blog.rb