Sha256: 8c5874705bb0e889671d9cd30bb30f45e8c4872f24ee9e00e9c58a8e6571a5bb

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

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
	
	##
	# Grab the title of the selected page/post
	
	def title
		post_title
	end
	
	##
	# Set the title of the selected page/post
	
	def title= new_title
		self.post_title = new_title
	end
	
	##
	# Grab the content of the selected page/post
	
	def content
		post_content
	end
	
	##
	# Set the content of the selected page/post
	
	def content= new_content
		self.post_content = new_content
	end
	
	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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wpb-0.0.6.pre lib/wpb/pagepost.rb
wpb-0.0.5 lib/wpb/pagepost.rb