summaryrefslogtreecommitdiff
path: root/app/models/wiki.rb
blob: d9ec069d14bf6d6eb2176e4f942ffa8bc0daffc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Wiki < ActiveRecord::Base
  belongs_to :project
  belongs_to :user
  has_many :notes, :as => :noteable, :dependent => :destroy

  validates :content, :title, :user_id, :presence => true
  validates :title, :length => 1..250

  before_update :set_slug

  def to_param
    slug
  end

  protected

  def set_slug
    self.slug = self.title.parameterize
  end

  class << self
    def regenerate_from wiki
      regenerated_field = [:slug, :content, :title]

      new_wiki = Wiki.new
      regenerated_field.each do |field|
        new_wiki.send("#{field}=", wiki.send(field))
      end
      new_wiki
    end

  end
end
# == Schema Information
#
# Table name: wikis
#
#  id         :integer(4)      not null, primary key
#  title      :string(255)
#  content    :text
#  project_id :integer(4)
#  created_at :datetime        not null
#  updated_at :datetime        not null
#  slug       :string(255)
#  user_id    :integer(4)
#