Module: Reform::Form::Validate
- Included in:
- Reform::Form
- Defined in:
- lib/reform/form/validate.rb
Overview
Mechanics for writing to forms in #validate.
Defined Under Namespace
Modules: Skip Classes: DeserializeError
Instance Method Summary collapse
-
#deserialize!(params) ⇒ Object
Meant to return params processable by the representer.
-
#validate(params) ⇒ Object
1.
Instance Method Details
#deserialize!(params) ⇒ Object
Meant to return params processable by the representer. This is the hook for munching date fields, etc.
33 34 35 36 37 38 39 |
# File 'lib/reform/form/validate.rb', line 33 def deserialize!(params) # NOTE: it is completely up to the form user how they want to deserialize (e.g. using an external JSON-API representer). # use the deserializer as an external instance to operate on the Twin API, # e.g. adding new items in collections using #<< etc. # DISCUSS: using self here will call the form's setters like title= which might be overridden. params end |
#validate(params) ⇒ Object
-
Populate the form object graph so that each incoming object has a representative form object.
-
Deserialize. This is wrong and should be done in 1.
-
Validate the form object graph.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reform/form/validate.rb', line 21 def validate(params) deprecate_update!(params) # allow an external deserializer. block_given? ? yield(params) : deserialize(params) super() # run the actual validation on self. # rescue Representable::DeserializeError # raise DeserializeError.new("[Reform] Deserialize error: You probably called #validate without setting up your nested models. Check https://github.com/apotonick/reform#populating-forms-for-validation on how to use populators.") end |