I have a site on PHP which I want to convert to Rails. I use md5 for password storage and _form partial for registration and edit users data. I made login and password fields required, thats work perfect for registration but when user try to edit his data, something like login, password field again need to fill (password field has password type and stay blank for editing). How I can use those form and solve problem with password enter in edit mode ?
Share
In your model, add a validation on your password fields only if they’ve been filled in, in other words, on update, the fields can be blank. If they are blank, then they will not be validated or changed.
You may also want to add a note on the form, the password fields are only required if you are changing your password or your email address.
You can check
object.new_record?(as Mr Yoshiji mentions) to determine if it’s a new record (no id yet) or an existing record to change your form hints.