0
votes

There is the following code:

@owner = Owner.find(params[:id])
if @owner.update(owner_params)
  # Some actions
else
  render 'edit'
end

'Owner' model has name, email, phone and 2 virtual attributes (for has_secure_password) : password and password_confirmation. I want to update only name, email and phone:

def owner_params
  params.require(:owner).permit(:name, :email, :phone)
end

But when I try to update Owner I get a message about blank password, because I use presence validation for password during creating. Please, tell me, is it possible to update only list of sending attributes passing validations other ones? Thanks in advance.

3
how about hidden_field? not sure.. - Nithin
are you using devise for authentication? - Rajdeep Singh

3 Answers

0
votes

If you are using Devise for authentication then there is a method named update_without_password, do this way

@owner.update_without_password(owner_params)
0
votes

Hope this one helps.

putting has_secure_password validations: false would work but you need to make custom validations after it

-1
votes

Use #update_attributes instead. It looks like #update runs the validation for all parameters (even with the missing ones).