Search code examples
ruby-on-railsruby-on-rails-4eachrails-4-2-1

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


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 =/


Solution

  • 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