Reputation: 1054
In the update action of my controller, I have this kind of code :
@loan.update_attributes(loan_params)
@loan.update_attributes(confirm: nil)
I want to make the same with only one request to the database. Do you know how to do it ?
Upvotes: 0
Views: 73
Reputation: 5411
assuming
def
params.require(:load).permit(:all_your_model_fields)
end
loan_params[:confirm] = nil
@loan.update(loan_params)
hope it help
Upvotes: 0
Reputation: 6015
I think this can help you
Probably loan_params will be a hash generated as loan => {:key => :val}
SO the confirm attribute will be merge to the the loan hash for updating the @loan
loan_params['loan'].merge!(confirm : nil)
@loan.update_attributes(loan_params)
Upvotes: 1
Reputation: 3866
Try this one :
loan_params.merge!(:confirm => nil)
@loan.update_attributes(loan_params)
or
loan_params.merge!(confirm: nil)
@loan.update_attributes(loan_params)
Thanks
Upvotes: 0
Reputation: 5734
Please have a Try with
loan_params[:confirm] = nil
@loan.update_attributes(loan_params)
Upvotes: 0