Module: HydraEditor::Form::ClassMethods
- Defined in:
- app/forms/hydra_editor/form.rb
Instance Method Summary collapse
- #build_permitted_params ⇒ Object
-
#model_attributes(form_params) ⇒ Object
Return a hash of all the parameters from the form as a hash.
- #multiple?(field) ⇒ Boolean
- #permitted_params ⇒ Object
- #sanitize_params(form_params) ⇒ Object
- #validators_on(*attributes) ⇒ Object
Instance Method Details
#build_permitted_params ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/forms/hydra_editor/form.rb', line 74 def build_permitted_params permitted = [] terms.each do |term| if multiple?(term) permitted << { term => [] } else permitted << term end end permitted end |
#model_attributes(form_params) ⇒ Object
Return a hash of all the parameters from the form as a hash. This is typically used by the controller as the main read interface to the form. This hash can then be used to create or update an object in the data store. example:
ImageForm.model_attributes(params[:image])
# => { title: 'My new image' }
58 59 60 61 62 63 64 |
# File 'app/forms/hydra_editor/form.rb', line 58 def model_attributes(form_params) clean_params = sanitize_params(form_params) terms.each do |key| clean_params[key].delete('') if clean_params[key] end clean_params end |
#multiple?(field) ⇒ Boolean
48 49 50 |
# File 'app/forms/hydra_editor/form.rb', line 48 def multiple?(field) .multiple?(model_class, field) end |
#permitted_params ⇒ Object
70 71 72 |
# File 'app/forms/hydra_editor/form.rb', line 70 def permitted_params @permitted ||= build_permitted_params end |
#sanitize_params(form_params) ⇒ Object
66 67 68 |
# File 'app/forms/hydra_editor/form.rb', line 66 def sanitize_params(form_params) form_params.permit(*permitted_params) end |