vendredi 1 décembre 2017

Rails: Only update attribute when specified in form

I have a form, in which users can add their birthday. Now currently, whenever someone submits this form, he will add a birthday, as the date input always has a value.

Is there a way I can add a checkbox - and only if it is checked, the birthday should be saved to the record? If the checkbox is not checked though, the current value for birthday should be removed.

= simple_form_for resource, as: resource_name, url: registration_url(resource_name) do |f|
    = f.input :another_field
    = f.input :birthday_set?, as: :boolean # or something else?
    = f.input :birthday
    = f.input :submit




Aucun commentaire:

Enregistrer un commentaire