gitlabhq/app/models/wiki.rb

56 lines
1.1 KiB
Ruby
Raw Normal View History

2012-02-19 15:35:31 +01:00
class Wiki < ActiveRecord::Base
attr_accessible :title, :content, :slug
2012-02-19 15:35:31 +01:00
belongs_to :project
2012-02-19 20:52:05 +01:00
belongs_to :user
has_many :notes, as: :noteable, dependent: :destroy
2012-02-19 15:35:31 +01:00
2012-10-09 02:10:04 +02:00
validates :content, presence: true
validates :user, presence: true
validates :title, presence: true, length: 1..250
2012-02-19 15:35:31 +01:00
2012-02-19 18:05:35 +01:00
before_update :set_slug
2012-02-19 15:35:31 +01:00
def to_param
slug
end
class << self
def search(query)
where("title like :query OR content like :query", query: "%#{query}%")
end
end
2012-02-19 15:35:31 +01:00
protected
2012-10-09 02:10:04 +02:00
def self.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
2012-02-19 15:35:31 +01:00
def set_slug
self.slug = self.title.parameterize
end
2012-02-19 18:05:35 +01:00
2012-02-19 15:35:31 +01:00
end
2012-09-27 08:20:36 +02:00
2012-02-28 14:09:23 +01:00
# == Schema Information
#
# Table name: wikis
#
2012-09-27 07:36:31 +02:00
# id :integer not null, primary key
2012-02-28 14:09:23 +01:00
# title :string(255)
# content :text
2012-09-27 07:36:31 +02:00
# project_id :integer
2012-02-28 14:09:23 +01:00
# created_at :datetime not null
# updated_at :datetime not null
# slug :string(255)
2012-09-27 07:36:31 +02:00
# user_id :integer
2012-02-28 14:09:23 +01:00
#
2012-10-09 10:14:17 +02:00