Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2.  
  3. ## in your form.html.haml
  4.  
  5. ``` javascript
  6. $(document).on('click', '.add_an_aol_field', function(){
  7. $aol_field = $('#aol_selector_template').html();
  8.  
  9. $('.aol_fields').append($aol_field);
  10. });
  11.  
  12. $(document).on('click', '.remove_this_aol_field', function(){
  13. $(this).closest('.aol_id_field').remove();
  14. });
  15. ```
  16.  
  17.  
  18. ```haml
  19. .aols
  20. .aol_fields
  21. - @profile.aols.each do |aol|
  22. = render('aols/aol_dropdown', aol: aol)
  23.  
  24. %a.add_an_aol_field add
  25.  
  26.  
  27.  
  28. %script{type="text" id="aol_selector_template"}
  29. = render('aols/aol_dropdown')
  30.  
  31. ```
  32.  
  33. ### params coming into controller
  34.  
  35. ```ruby
  36.  
  37. params = {
  38. attorney_profile: {
  39. aol_ids: [1, 3, 35]
  40. }
  41. }
  42.  
  43. ```
  44.  
  45. ### inside app/views/aols/_aol.html.haml
  46.  
  47. ``` haml
  48. .aol_id_field
  49. %select{name="attorney_profile[aol_ids][]"}
  50. - @aols.each do |aol|
  51. %option{value: aol.id}= aol.name
  52.  
  53. %a.remove_this_aol_field X
  54.  
  55. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement