vendredi 15 avril 2016

Receive params and save in other model and remove error Couldn't find Authorization with 'id'= 0

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
    params[:authorization][:contract_ids].each_with_index do |id, index|
      Authorization.find(id).update_column(value_solve: params[:authorization][:value_solve], situation: 2)
    end
  end

This is my console:

  Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"123456789", "authorization"=>{"contract_ids"=>["11"], "value_solve"=>["334545", "", ""]}, "commit"=>"Reserve"}
Completed 500 Internal Server Error in 18ms (ActiveRecord: 0.6ms)

And the error is:

Couldn't find Authorization with 'id'= 0

My view is correct. Other thing. Refinancing belongs_to :authorization and Authorizarion has_many :refinancings When I checked, the id of checkboxes clicked pass ok and the value_solve too, but the situation don't change and nothing save on db




Aucun commentaire:

Enregistrer un commentaire