]> git.openstreetmap.org Git - rails.git/blob - app/models/diary_entry.rb
Made rubocop happy by formatting and minor syntax tweaks.
[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 :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
19
20   after_save :spam_check
21
22   def body
23     RichText.new(self[:body_format], self[:body])
24   end
25
26   private
27
28   def spam_check
29     user.spam_check
30   end
31 end