app/models/binda/field_group.rb in binda-0.0.5 vs app/models/binda/field_group.rb in binda-0.0.6

- old
+ new

@@ -15,10 +15,11 @@ # Slug extend FriendlyId friendly_id :default_slug, use: [:slugged, :finders] + after_create :update_position # CUSTOM METHODS # -------------- # https://github.com/norman/friendly_id/issues/436 def should_generate_new_friendly_id? @@ -33,8 +34,16 @@ end def is_rejected( attributes ) attributes['name'].blank? && attributes['field_type'].blank? end + + private + + def update_position + if self.position.nil? + self.update_attribute( 'position', self.structure.field_groups.length ) + end + end end end