Added a concept of default values to forms. Also includes using models & #5634
+156
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Link to pivotal/JIRA issue
Is PM acceptance required? (delete one)
Reminder: merge main into this branch and get green tests before merging to main
What was done?
When you use a form's
set_attributes_for
on fields with defaults and don't set a value, you can get database level failures. This provides two possible fixes; either:a. Specifically provide a
defaults
dictionary orb. Use a model rather than a symbol for the first argument to
set_attributes_for
When doing the latter, we inspect the
column_defaults
on the model and populate the default values with which we initialize the form, so they will never be nil without being explicitly set to nil.This behavior is opt in and uses new arguments and reflection on the model. It should change no other behavior.
This resolves issues like the ones seen on update_13614c_form_page1.
It will also set us up well for a default
QuestionsForm#save
method; if all keys are models, then we can assume that their respective attributes are available and we can save it out.How to test?
Screenshots (for visual changes)