2012-02-19 15:35:31 +01:00
|
|
|
class Wiki < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
2012-02-19 20:52:05 +01:00
|
|
|
belongs_to :user
|
2012-02-19 15:35:31 +01:00
|
|
|
|
2012-02-19 20:52:05 +01:00
|
|
|
validates :content, :title, :user_id, :presence => true
|
2012-02-19 18:05:35 +01:00
|
|
|
validates :title, :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
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def set_slug
|
|
|
|
self.slug = self.title.parameterize
|
|
|
|
end
|
2012-02-19 18:05:35 +01:00
|
|
|
|
|
|
|
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
|
2012-02-19 15:35:31 +01:00
|
|
|
end
|