foodsoft/app/models/page.rb

19 lines
482 B
Ruby
Raw Normal View History

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