Module: Alchemy::Page::PageElements::ClassMethods

Defined in:
app/models/alchemy/page/page_elements.rb

Instance Method Summary collapse

Instance Method Details

#copy_elements(source, target) ⇒ Array

Copy page elements

Parameters:

Returns:

  • (Array)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/alchemy/page/page_elements.rb', line 43

def copy_elements(source, target)
  new_elements = []
  source.elements.not_trashed.each do |source_element|
    cell = nil
    if source_element.cell
      cell = target.cells.find_by(name: source_element.cell.name)
    end
    new_element = Element.copy source_element, {
      page_id: target.id,
      cell_id: cell.try(:id)
    }
    new_element.move_to_bottom
    new_elements << new_element
  end
  new_elements
end