X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e93241899820c5661de9dad8b86342966808a1e4..6c51b3cc0ad7e193c7dae3794502088faab37c7b:/app/models/note.rb diff --git a/app/models/note.rb b/app/models/note.rb index 490ff43cb..9dc122721 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -1,10 +1,7 @@ class Note < ActiveRecord::Base include GeoRecord - has_many :comments, :class_name => "NoteComment", - :foreign_key => :note_id, - :order => :created_at, - :conditions => { :visible => true } + has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id validates_presence_of :id, :on => :update validates_uniqueness_of :id @@ -14,8 +11,6 @@ class Note < ActiveRecord::Base validates_inclusion_of :status, :in => ["open", "closed", "hidden"] validate :validate_position - attr_accessible :lat, :lon - after_initialize :set_defaults # Sanity check the latitude and longitude and add an error if it's broken @@ -30,6 +25,13 @@ class Note < ActiveRecord::Base self.save end + # Reopen a note + def reopen + self.status = "open" + self.closed_at = nil + self.save + end + # Check if a note is visible def visible? status != "hidden"