ruby-on-railsarraysruby-on-rails-4rails-4-2-1

No implicit conversion of Symbol into Integer. A error still no solution for me


I have a view with checkboxes and input text. I checked one checkbox and digit value on input, after submit. But have two problem... A error on params and don't save the values on my table, this is my code:

refinancings_controller.rb

 def new
    if params[:authorization]
      @selected_ids = params[:authorization][:contract_ids]
      @authorizations = Authorization.where("contract_number in (?)", @selected_ids)
    end
    @employee = Employee.search_cpf(params[:search_employee_by_cpf])
    @refinancing = Refinancing.new
    Authorization.where(id: params[:authorization][:contract_ids]).update_all(value_solve: params[:authorization][:value_solve], situation: 2)
  end

My console this is:

Processing by RefinancingsController#new as HTML
  Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"11111111111", "authorization"=>{"value_solve"=>["", "3444555", ""], "contract_ids"=>["33"]}, "commit"=>"Reserve"}
Completed 500 Internal Server Error in 11ms (ActiveRecord: 0.3ms)

TypeError (no implicit conversion of Symbol into Integer):
  app/controllers/refinancings_controller.rb:37:in `[]'
  app/controllers/refinancings_controller.rb:37:in `new'

This is a first error:

no implicit conversion of Symbol into Integer

The other error is don't show params situation...


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