page_datum.rb
834 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
module Kanjai
class PageDatum < ActiveRecord::Base
belongs_to :page
has_many :page_contents
validates :title, :page_id, :lang, presence: true
serialize :template_content, Array
after_save :delete_not_exist_content
def delete_not_exist_content
self.template_content ||= []
exist_id = []
self.template_content.each do |row|
row['attributes'] ||= {}
if row['attributes']['id'].present?
exist_id << row['attributes']['id']
end
row["cells"].each do |cell|
exist_id << cell['id']
end
end
self.page_contents.where('structure_id not in (?)', exist_id).each do |item|
item.destroy
end
end
def last_modified
updated_at.utc
end
def etag_cache_key
cache_key
end
end
end