Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
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
This paste will be private.
From the Design Piracy series on my blog: