1 class DiaryEntry < ActiveRecord::Base
2 belongs_to :user, :counter_cache => true
3 belongs_to :language, :foreign_key => "language_code"
5 has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
6 has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w(active confirmed) }).order(:id) }, :class_name => "DiaryComment"
8 scope :visible, -> { where(:visible => true) }
10 validates :title, :body, :presence => true
11 validates :title, :length => 1..255
12 validates :latitude, :allow_nil => true,
13 :numericality => { :greater_than_or_equal_to => -90,
14 :less_than_or_equal_to => 90 }
15 validates :longitude, :allow_nil => true,
16 :numericality => { :greater_than_or_equal_to => -180,
17 :less_than_or_equal_to => 180 }
18 validates :language, :user, :associated => true
20 after_save :spam_check
23 RichText.new(self[:body_format], self[:body])