Couldn't find Authorization with 'id'=0 using each_with_index

55 views Asked by At

I have this error and this is my code:

 params[:authorization][:contract_ids].each_with_index do |index, id|
      Authorization.find(id).update_column(value_solve: params[:authorization][:value_solve])
    end

This started with 0, and Authorization have id 1 and forward. How solve this? I tried many things but nothing don't worked =/

2

There are 2 answers

0
Elton Santos On BEST ANSWER

The answer this is:

      auth_params = params[:authorization]
auth_params[:contract_number].zip(auth_params[:value_solve].reject(&:blank?)).each do |contract_number, value_solve|
          Authorization.where(contract_number: contract_number).update_all(value_solve: value_solve, situation: 2)
      end

:D

1
7urkm3n On

I see, you are not even using index, just go straight with .each looping.

Try this one:

 params[:authorization][:contract_ids].each do |id|
      Authorization.find(id).update_column(value_solve: params[:authorization][:value_solve])
 end