Sha256: 3ce2d36af6402aa15c7b9f9acdc0c1557f87c2933590e9b0d17272f671046cc0

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

module MegaBar
  class LayoutSection < ActiveRecord::Base
    attr_accessor :template_section_id, :model_id, :block_text, :base_name, :new_model_display, :edit_model_display, :index_model_display, :show_model_display

    has_many :layables, dependent: :destroy
    has_many :layouts, through: :layables
    has_many :blocks, dependent: :destroy
    validates_presence_of :code_name
    validates_uniqueness_of :code_name

    after_create :create_block_for_section

    def create_block_for_section
      # path_base:  MegaBar::Page.find(self.page_id).path, # could be added in below. but doesnt look necessary.
      block_hash = {layout_section_id: self.id, name: self.code_name.humanize + ' Block', actions: 'current', model_id: self.model_id, new_model_display: 'y', edit_model_display: 'y', index_model_display: 'y', show_model_display: 'y'}
      block_hash = block_hash.merge(html: self.block_text) if self.block_text
      Block.create(block_hash)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mega_bar-0.5.2 app/models/mega_bar/layout_section.rb
mega_bar-0.5.1 app/models/mega_bar/layout_section.rb