foodsoft/app/models/page.rb
2009-05-15 17:32:45 +02:00

18 lines
449 B
Ruby

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