published_article.rb
936 Bytes
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
class PublishedArticle < Article
before_create do |article|
unless article.parent
parent = article.reference_article.parent
if parent && parent.blog? && article.profile.has_blog?
article.parent = article.profile.blog
end
end
end
def self.short_description
_('Reference to other article')
end
def self.description
_('A reference to another article published in another profile')
end
before_validation_on_create :update_name
def update_name
self.name = self.reference_article.name if self.name.blank?
end
def author
if reference_article
reference_article.author
else
profile
end
end
def to_html(options={})
reference_article ? reference_article.to_html : ('<em>' + _('The original text was removed.') + '</em>')
end
def abstract
reference_article && reference_article.abstract
end
def notifiable?
true
end
end