Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  user = User.find_by_name("magmarules")
  section = Section.find_by_id(3)

  event = Sale.new
  #event.user_id = user.id
  event.title = "Sale"
  event.save

  section.events << event

  event2 = Event.new
  #event.user_id = user.id
  event2.title = "Generic Event"
  event2.save

  section.events << event2
  section.save

############

module EventBase
  def creator
    User.find_by_id(user_id)
  end
end

class SectionEvent < ActiveRecord::Base
  belongs_to :section

  belongs_to :event, :polymorphic => true
end

class Event < ActiveRecord::Base

  include EventBase

  belongs_to :user

end

class Sale < ActiveRecord::Base
  include EventBase

  belongs_to :user
end

class Section < ActiveRecord::Base
  has_many :messages

  has_many_polymorphs :events, :through => :section_events, :from => [:sales, :events] #:meetings]

  validates_presence_of :title, :description
  validates_uniqueness_of :title
  acts_as_authorizable

end