Sha256: b723f49f70ad9948ee354da99b82f9ebc8081632461d642326a3eda581b5b728
Contents?: true
Size: 836 Bytes
Versions: 65
Compression:
Stored size: 836 Bytes
Contents
class CamaleonCms::Widget::Sidebar < CamaleonCms::TermTaxonomy default_scope { where(taxonomy: :sidebar) } has_many :metas, ->{ where(object_class: 'Widget::Sidebar')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy has_many :assigned, foreign_key: :post_parent, dependent: :destroy belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id #scopes scope :default_sidebar, -> { where(:slug => 'default-sidebar') } scope :all_sidebar, -> { where("slug != 'default-sidebar'") } # assign the widget into this sidebar # widget: string(slug)/object # data: {title, content} def add_widget(widget, data = {}) widget = self.site.widgets.where(slug: widget).first if widget.is_a?(String) data[:widget_id] = widget.id self.assigned.create(data) end end
Version data entries
65 entries across 65 versions & 2 rubygems