2009-03-25 19:54:04 +01:00
|
|
|
class Page < ActiveRecord::Base
|
|
|
|
|
2009-05-15 17:32:45 +02:00
|
|
|
belongs_to :user, :foreign_key => 'updated_by'
|
|
|
|
|
2009-05-20 15:26:53 +02:00
|
|
|
acts_as_versioned :version_column => :lock_version
|
2009-05-15 17:32:45 +02:00
|
|
|
self.non_versioned_columns += ['permalink', 'created_at']
|
|
|
|
|
2009-03-25 19:54:04 +01:00
|
|
|
validates_presence_of :title, :body
|
2009-05-13 17:32:43 +02:00
|
|
|
validates_uniqueness_of :permalink
|
2009-03-25 19:54:04 +01:00
|
|
|
|
2009-05-13 17:32:43 +02:00
|
|
|
before_validation_on_create :set_permalink
|
2009-03-25 19:54:04 +01:00
|
|
|
|
|
|
|
def set_permalink
|
2009-05-13 17:32:43 +02:00
|
|
|
if self.permalink.blank?
|
2009-03-25 19:54:04 +01:00
|
|
|
self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(/ |\.|@/, '-')}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|