29 lines
691 B
Ruby
29 lines
691 B
Ruby
class PagePart
|
|
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :name
|
|
field :content
|
|
field :kind
|
|
field :i18n_variable_id, :type => BSON::ObjectId
|
|
|
|
belongs_to :page
|
|
|
|
# Get the i18n_variable
|
|
def i18n_variable
|
|
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
|
end
|
|
|
|
# Update or create the i18n_variable record
|
|
def i18n_variable=(attr)
|
|
if self.i18n_variable_id
|
|
self.i18n_variable.update_attributes(attr)
|
|
else
|
|
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
|
var.save
|
|
self.i18n_variable_id = var.id
|
|
end
|
|
end
|
|
|
|
end |