     to_remove = $(@).closest 'fieldset'
     recompute_positions parent
 
-    parent.trigger 'has_many_remove:before', [ to_remove ]
+    parent.trigger 'has_many_remove:before', [to_remove]
     to_remove.remove()
 
   # Provides before and after creation hooks:

  position   = 0

  parent.children('fieldset').each ->
    fieldset = $(@)
    # when looking for inputs, we ignore inputs from the possibly nested inputs
    # so, when defining your has_many, make sure to keep the sortable input at the root of the has_many block
    destroy_input  = fieldset.find "> ol > .input > :input[name$='[_destroy]']"
    sortable_input = fieldset.find "> ol > .input > :input[name$='[#{input_name}]']"

    if sortable_input.length
      sortable_input.val if destroy_input.is ':checked' then '' else position++

  #
  $(document).on 'click', 'a.button.has_many_add', (e)->
    e.preventDefault()
    parent = $(@).closest '.has_many_container'
    parent.trigger before_add = $.Event 'has_many_add:before'

    unless before_add.isDefaultPrevented()
      index = parent.data('has_many_index') || parent.children('fieldset').length - 1
      parent.data has_many_index: ++index

      regex = new RegExp $(@).data('placeholder'), 'g'
      html  = $(@).data('html').replace regex, index

      fieldset = $(html).insertBefore(@)
      recompute_positions parent
      parent.trigger 'has_many_add:after', [fieldset]

  $(document).on 'change','.has_many_container[data-sortable] :input[name$="[_destroy]"]', ->
    recompute_positions $(@).closest '.has_many'
