Class: Binda::Repeater

Inherits:
ApplicationRecord show all
Includes:
FieldableAssociations, Fields
Defined in:
app/models/binda/repeater.rb

Instance Method Summary collapse

Methods included from FieldableAssociations

#find_or_create_a_field_by, #generate_fields

Instance Method Details

#set_default_positionobject

Set default position after create

This methods ensure that every repeater instance has an explicit position.

The latest repeater created gets the highest position number.

Returns:

  • (object)

    Repeater instance



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

def set_default_position
    Repeater
        .where(
            field_setting_id: self.field_setting_id,
            fieldable_id: self.fieldable_id,
            fieldable_type: self.fieldable_type
        )
        .each{|repeater| repeater.increment(:position).save!}
end