RailsConf 2017 Form Object
2020-02-27 304浏览
- 1.Decouple your models with FORM OBJECTS
- 2.
- 3.data model == form
- 4.data model == form accepts_nested_attributes_for
- 5.session[:user_attributes] = @user.all_the_attributes store data in the session
- 6.
- 7.state machine
- 8.classDog::BreedDetails< Dog nested models
- 9.VIEW view > model MODEL
- 10.Let’s not do it!
- 11.Form Objects
- 12.3 FORM OBJECT What is a form object?
- 13.3 FORM OBJECT What is a form object? <%= form_for(@person) do f %> <%= f.input :name %> <%= f.button :submit, 'Submit' %> <% end %>
- 14.3 FORM OBJECT
- 15.3 FORM OBJECT
- 16.
- 17.Form 1 - Nested Data DATA MODEL Company name time_zone kind Phone Address address city state zip country_code number Account subscription_type User first_name last_name
- 18.Form 2 - Custom Logic DATA MODEL Company name time_zone kind Phone Address address city state zip country_code number Account subscription_type User first_name last_name
- 19.Form 3 - Data Scatter DATA MODEL Company name time_zone kind Phone Address address city state zip country_code number Account subscription_type User first_name last_name
- 20.3 FORM OBJECT
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.3 FORM OBJECT
- 89.3 FORM OBJECT
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.3 FORM OBJECT
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.Prepopulators Populators
- 107.Prepopulators :new, :edit called manually with .prepopulate! prepares the form for rendering can fill out fields in the form Populators
- 108.Prepopulators Populators :new, :edit :create, :update called manually with .prepopulate! called every time when you .validate prepares the form for rendering can fill out fields in the form prepares the form for validating cares about matching the right data to the right model
- 109.
- 110.
- 111.
- 112.
- 113.Form 1 - Nested Data DATA MODEL Company name time_zone kind Phone Address address city state zip country_code number Account subscription_type User first_name last_name
- 114.
- 115.
- 116.3 FORM OBJECT
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.3 FORM OBJECT
- 142.
- 143.Form 3 - Data Scatter DATA MODEL Company name time_zone kind Phone Address address city state zip country_code number Account subscription_type User first_name last_name
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.4 A D V A N TA G E S Advantages
- 166.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 167.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 168.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 169.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 170.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 171.4 A D V A N TA G E S ‣ Model agnostic ‣ Validation is context-specific Form Objects ‣ RESTful ‣ Easy to test ‣ Easy to extend and modify ‣ Use when you need to
- 172.The end.
- 173.attributesHTTPS://FORUM.UPCASE.COM/T/FORM-OBJECTS/2267H T T P S : / / R O B O T S . T H O U G H T B O T. C O M / A C T I V E M O D E L - F O R M - O B J E C T SHTTP://TRAILBLAZER.TO/GEMS/REFORM'>HTTP://TRAILBLAZER.TO/GEMS/REFORM