Method: Cms::Concerns::CanBeAddressable#is_addressable
- Defined in:
- lib/cms/concerns/can_be_addressable.rb
#is_addressable(options = {}) ⇒ Object
Adds Addressable behavior to a model. This allows models to be inserted into the sitemap, having parent sections. By default, this method is available to all ActiveRecord::Base classes.
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 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cms/concerns/can_be_addressable.rb', line 12 def is_addressable(={}) = {as: :node, inverse_of: :node, class_name: 'Cms::SectionNode', validate: true} unless [:destroy_if] [:dependent] = :destroy else before_destroy [:destroy_if] after_destroy :destroy_node end has_one :section_node, # For reasons that aren't clear, just using :autosave doesn't work. after_save do if section_node && section_node.changed? section_node.save end end after_validation do # Copy errors from association for slug if section_node && !section_node.valid? section_node.errors[:slug].each do || errors.add(:slug, ) end end end include Cms::Concerns::Addressable extend Cms::Concerns::Addressable::ClassMethods include Cms::Concerns::Addressable::NodeAccessors include Cms::Concerns::Addressable::MarkAsDirty extend Cms::Configuration::ConfigurableTemplate if [:path] @path = [:path] include GenericSitemapBehavior end @template = [:template] unless [:no_dynamic_path] include Addressable::DynamicPath end end |