]> git.openstreetmap.org Git - rails.git/blob - app/models/diary_entry.rb
Convert OpenID authentication to generic third party authentication
[rails.git] / app / models / diary_entry.rb
1 class DiaryEntry < ActiveRecord::Base
2   belongs_to :user, :counter_cache => true
3   belongs_to :language, :foreign_key => "language_code"
4
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"
7
8   scope :visible, -> { where(:visible => true) }
9
10   validates_presence_of :title, :body
11   validates_length_of :title, :within => 1..255
12   # validates_length_of :language, :within => 2..5, :allow_nil => false
13   validates_numericality_of :latitude, :allow_nil => true,
14                                        :greater_than_or_equal_to => -90, :less_than_or_equal_to => 90
15   validates_numericality_of :longitude, :allow_nil => true,
16                                         :greater_than_or_equal_to => -180, :less_than_or_equal_to => 180
17   validates_associated :language
18
19   after_save :spam_check
20
21   def body
22     RichText.new(read_attribute(:body_format), read_attribute(:body))
23   end
24
25   private
26
27   def spam_check
28     user.spam_check
29   end
30 end