app/models/kuhsaft/brick.rb in kuhsaft-1.1.1 vs app/models/kuhsaft/brick.rb in kuhsaft-1.2.0

- old
+ new

@@ -21,13 +21,23 @@ :type, :brick_list_id, :brick_list_type, :presence => true + after_initialize do + self.position ||= has_siblings? ? brick_list.bricks.maximum(:position).to_i + 1 : 1 + end + def to_edit_partial_path path = self.to_partial_path.split '/' path << 'edit' path.join '/' + end + + def has_siblings? + if brick_list + brick_list.bricks.any? + end end # # The child partial can contain your own implementation # of how the brick renders it's child in the edit form.