article_block.rb
723 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
class ArticleBlock < Block
def self.description
_('Display one of your contents.')
end
def content
article ? article.to_html : _('Article not selected yet.')
end
def article_id
self.settings[:article_id]
end
def article_id= value
self.settings[:article_id] = value
end
def article(reload = false)
@article = nil if reload
if @article || article_id
begin
@article = Article.find(article_id)
rescue ActiveRecord::RecordNotFound
# dangling reference, clear it
@article = nil
self.article_id = nil
self.save!
end
end
@article
end
def article=(obj)
self.article_id = obj.id
@article = obj
end
end