Sha256: dfe8a79abf626106afdaff60a2c320a88e537d95886b3140d85d24b20df4ae9f
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
class Page < ActiveRecord::Base include PublicActivity::Common include Tire::Model::Search include Tire::Model::Callbacks has_ancestry #touch: true acts_as_list scope: [:ancestry] acts_as_taggable attr_accessor :old_ancestor_ids belongs_to :creator_id has_many :attachments, as: :attachable, dependent: :destroy validates_presence_of :creator validates_presence_of :title belongs_to :creator, class_name: 'User' after_save :touch_ancestry def to_param [id, title.parameterize].join("-") end def wiki_dir "/wiki/#{id}" end def update_to_gollum(user) commit = { message: 'no message', name: user.name, email: user.email } body_page = "#{id}-body" title_page = "#{id}-title" $wiki.write_page("/" + body_page, :textile, body, commit, wiki_dir) $wiki.write_page("/" + title_page, :textile, title, commit, wiki_dir) end def type @type || "Page" end def last_updated activities. where(key: 'page.update_details'). order("created_at desc").first || activities.where(key: 'page.created'). order("created_at desc").first end def versions $wiki.page("#{id}-body", nil, wiki_dir).try(:versions) || [] end def reorder!(options) if options[:parent_id] self.old_ancestor_ids = self.ancestor_ids self.parent_id = options[:parent_id] self.save end self.insert_at options[:position].to_i self.save end def touch_ancestry self.old_ancestor_ids ||= [] Page.where(id: (ancestor_ids + old_ancestor_ids).uniq).update_all(updated_at: Time.now) end private end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tawork-0.0.19 | app/models/page.rb |
tawork-0.0.18 | app/models/page.rb |