Class: BlockSlot

Inherits:
Forest::ApplicationRecord show all
Defined in:
app/models/block_slot.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Forest::ApplicationRecord

cache_key, cache_key_name, csv_columns, #expire_cache_key, expire_cache_key, statusable?, #statusable?, to_csv_template, #to_friendly_param, #to_label, #to_select2_response, #to_select2_selection, versionable, #versionable

Class Method Details

.blockable_paramsObject

Merge these blockable params into the blockable record’s strong params



19
20
21
22
23
24
25
26
27
28
# File 'app/models/block_slot.rb', line 19

def self.blockable_params
  {
    block_slots_attributes: [
      :id, :_destroy, :position,
      :block_type, :block_record_type,
      :block_id, :block_kind_id, :block_layout_id, :block_record_id,
      block_attributes: [*BlockKind.block_kind_params]
    ]
  }
end

Instance Method Details

#block_attributes=(attributes) ⇒ Object



30
31
32
33
34
35
# File 'app/models/block_slot.rb', line 30

def block_attributes=(attributes)
  if BlockKind.where(name: self.block_kind.name).exists?
    self.block ||= self.block_kind.name.constantize.new
    self.block.assign_attributes(attributes)
  end
end

#create_block_if_block_attributes_emptyObject



37
38
39
40
41
# File 'app/models/block_slot.rb', line 37

def create_block_if_block_attributes_empty
  if BlockKind.where(name: self.block_kind.name).exists? && BlockKind.where(name: self.block_kind.name).first.block.permitted_params.blank?
    self.block ||= self.block_kind.name.constantize.new
  end
end