Skip to content

Instantly share code, notes, and snippets.

@Sporky023
Last active February 11, 2016 01:03
Show Gist options
  • Save Sporky023/28cbe447d056c66b7479 to your computer and use it in GitHub Desktop.
Save Sporky023/28cbe447d056c66b7479 to your computer and use it in GitHub Desktop.

in your form.html.haml

  $(document).on('click', '.add_an_aol_field', function(){
    $aol_field = $('#aol_selector_template').html();

    $('.aol_fields').append($aol_field);
  });

  $(document).on('click', '.remove_this_aol_field', function(){
    $(this).closest('.aol_id_field').remove();
  });
.aols
  .aol_fields
    - @profile.aols.each do |aol|
      = render('aols/aol_dropdown', aol: aol)

  %a.add_an_aol_field add



%script{type="text" id="aol_selector_template"}
  = render('aols/aol_dropdown')

params coming into controller

params = {
  attorney_profile: {
    aol_ids: [1, 3, 35]
  }
}

inside app/views/aols/_aol.html.haml

  .aol_id_field
    %select{name="attorney_profile[aol_ids][]"}
      - @aols.each do |aol|
        %option{value: aol.id}= aol.name

    %a.remove_this_aol_field X
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment