forked from publify/publify
/
page.rb
48 lines (38 loc) · 889 Bytes
/
page.rb
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
48
class Page < Content
belongs_to :user
validates_presence_of :title, :body
validates_uniqueness_of :name
include ConfigManager
serialize :settings, Hash
setting :password, :string, ''
before_save :set_permalink
after_save :shorten_url
def set_permalink
self.name = self.title.to_permalink if self.name.blank?
end
def initialize(*args)
super
# Yes, this is weird - PDC
begin
self.settings ||= {}
rescue Exception => e
self.settings = {}
end
end
content_fields :body
def self.default_order
'name ASC'
end
def self.search_with(search_hash)
super(search_hash).order('title ASC')
end
def permalink_url(anchor=nil, only_path=false)
blog.url_for(
:controller => '/articles',
:action => 'view_page',
:name => name,
:anchor => anchor,
:only_path => only_path
)
end
end