app/models/locomotive/editable_element.rb in locomotive_cms-2.0.3 vs app/models/locomotive/editable_element.rb in locomotive_cms-2.1.0
- old
+ new
@@ -6,27 +6,27 @@
## fields ##
field :slug
field :block
field :hint
- field :priority, :type => Integer, :default => 0
- field :fixed, :type => Boolean, :default => false
- field :disabled, :type => Boolean, :default => false, :localize => true
- field :from_parent, :type => Boolean, :default => false
- field :locales, :type => Array, :default => []
+ field :priority, type: Integer, default: 0
+ field :fixed, type: Boolean, default: false
+ field :disabled, type: Boolean, default: false, localize: true
+ field :from_parent, type: Boolean, default: false
+ field :locales, type: Array, default: []
## associations ##
- embedded_in :page, :class_name => 'Locomotive::Page', :inverse_of => :editable_elements
+ embedded_in :page, class_name: 'Locomotive::Page', inverse_of: :editable_elements
## validations ##
validates_presence_of :slug
## callbacks ##
- after_save :propagate_content, :if => :fixed?
+ after_save :propagate_content, if: :fixed?
## scopes ##
- scope :by_priority, :order_by => [[:priority, :desc]]
+ scope :by_priority, order_by(priority: :desc)
## methods ##
def disabled?
!!self.disabled # the original method does not work quite well with the localization
@@ -59,9 +59,14 @@
# Each editable element overrides this method.
#
# @param [ Hash ] attributes The up-to-date attributes
#
def copy_attributes(attributes)
+ # _type is among the mass-assign protected attributes.
+ if type = attributes.delete(:_type)
+ self._type = type
+ end
+
self.attributes = attributes
end
# Copy attributes from an existing editable element coming
# from the parent page. Each editable element may or not