Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2a09b1405e
Fetching contributors…

Cannot retrieve contributors at this time

70 lines (54 sloc) 1.529 kb
class WikiPage < ActiveRecord::Base
extend FriendlyId
include Rails.application.routes.url_helpers
include WikiPageUser
before_save :set_main_page
acts_as_versioned :extend => WikiPageUser
friendly_id :title, :use => :slugged
validates_presence_of :title
def title_from_id=(id)
self.title = id.to_s.underscore.humanize if id
end
belongs_to :project
self.non_versioned_columns << :project_id
self.non_versioned_columns << :title
self.non_versioned_columns << :slug
scope :main, lambda{ |project| where(:main => true, :project_id => project.id) }
after_create :process_create
before_update :process_update_params
before_destroy :process_destroy
def scope_value
project.id.to_s
end
def process_create
Activity.new_log(self, created_by, :add)
end
def process_update_params
Activity.new_log(self, created_by, :edit)
end
def process_destroy
Activity.new_log(self, created_by, :delete)
end
def object_name
title
end
def object_url(host = nil)
url_for :only_path => host.nil?, :host => host, :controller => 'wiki_pages', :action => 'show', :id => self, :active_project => project_id
end
# Indexing
define_index do
indexes :title
indexes :content
has :project_id
has :created_at
has :updated_at
end
protected
def main_page
@main_page ||= WikiPage.main(project).first
end
def set_main_page
main_page.update_attribute :main, false if main && !main_was && main_page
true
end
end
Jump to Line
Something went wrong with that request. Please try again.