require "active_record" class PagePost < ActiveRecord::Base set_table_name :wp_posts set_primary_key :ID before_save :update_date before_create :set_default_values validates_presence_of :post_author has_many :comments, :foreign_key => :comment_post_ID alias_attribute :title, :post_title alias_attribute :content, :post_content private def set_default_values t = Time.now self.post_date = t self.post_date_gmt = t.gmtime # Ready for when Site model is added # site_url = Site.find_by_option_name "siteurl" # type = 'p' # if self.type == "Page" # type << 'age_id' # end # self.guid = "#{site_url}/?#{type}=#{self.id}" urlify = self.post_title.dup.downcase.gsub(' ', '-') self.post_name = urlify end def update_date t = Time.now self.post_modified = t self.post_modified_gmt = t.gmtime end end