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
|
# File 'lib/acts_as_content_node/content_node.rb', line 5
def acts_as_content_node
belongs_to :updated_by, :class_name => 'User'
belongs_to :created_by, :class_name => 'User'
named_scope :authored_by, lambda { |user|
return {} if user.nil?
user = User.find(user) unless user.is_a? ::User
{ :conditions => { :created_by_id => user.id } }
}
before_validation :set_url
validates_presence_of :title
validates_uniqueness_of :permalink, :message => 'has been used before', :if => (:permalink_written && :publish)
attr_reader :permalink_written
def find_by_permalink(permalink)
content_node = find(:first, :conditions => ['permalink = ?', permalink])
raise ActiveRecord::RecordNotFound, "Couldn't find #{name} with permalink #{permalink}" if content_node.nil?
content_node
end
acts_as_publishable
send :include, InstanceMethods
end
|