I got a nested form using the cocoon gem:

\_form.html.haml:

```
= simple_form_for @day do |f|
  #task
    = f.simple_fields_for :tasks do |task|
      = render 'task_fields', f: task
    .links
      = link_to_add_association '+ Aufgabe', f, :tasks
  = f.submit

```

\_task\_fields.html.haml:

```
.nested-fields
  = f.input :description, label: 'Name/Beschreibung: '
  = f.input :ur, as: :range, input_html: { min: '1', max: '4', id: "rangeInput#{@x}", oninput: "rangeOutput#{@x}.value = rangeInput#{@x}.value"}
  %output#rangeOutput{:for => "rangeInput#{@x}", :name => "rangeOutput#{@x}"} 3

  = link_to_remove_association "remove task", f

```

days\_controller.rb:

```
def create
  @day = current_user.days.build(day_params)
  @day.save
  respond_to do |format|
    if @day.save
      format.html { redirect_to @day, notice: 'Day was successfully created.' }
      format.json { render :show, status: :created, location: @day }
    else
      format.html { render :new }
      format.json { render json: @day.errors, status: :unprocessable_entity }
    end
  end
end

```

I need to increment a viariable evertime the `_task_fields-partial` is rendered or the `link_to_add_association` is pressed.