Add object to calentries

This commit is contained in:
Andreas Stephanides
2013-08-23 13:39:54 +02:00
parent abc5ce04a3
commit de4c84871c
2 changed files with 23 additions and 1 deletions

View File

@@ -16,14 +16,21 @@ class Calentry < ActiveRecord::Base
has_and_belongs_to_many :calendars has_and_belongs_to_many :calendars
validates :start, :presence => true validates :start, :presence => true
validates :typ, :presence => true validates :typ, :presence => true
before_save :get_public
belongs_to :object, polymorphic: true
validate do |entry| validate do |entry|
if entry.ende.nil? if entry.ende.nil?
errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein") errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein")
end end
end end
belongs_to :object, polymorphic: true
resourcify resourcify
def get_public
self.public = (self.try(:object).nil?)? (self.calendars.public.count>0) : object.try(:public)
true
end
def start_time def start_time
start start
end end
@@ -33,5 +40,6 @@ class Calentry < ActiveRecord::Base
def name def name
summary summary
end end
scope :public, -> { where(:public => :true) }
scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 8.days.from_now) } scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 8.days.from_now) }
end end

View File

@@ -0,0 +1,14 @@
class AddObjectToCalentries < ActiveRecord::Migration
def up
add_column :calentries,:object_id, :integer
add_column :calentries,:object_type, :string
add_column :calentries, :public, :boolean
Calentry.update_all(:public => :true)
end
def down
remove_column :calentries, :object_id
remove_column :calentries,:object_type
remove_column :calentries,:public
end
end