Someone can help me please? I posted on stackoverflow here:
My problem is this:
def new
if params[:authorization].present?
@selected_ids = params[:authorization][:contract_ids]
@authorizations = Authorization.where("contract_number in (?)", @selected_ids)
Authorization.where(id: params[:authorization][:contract_ids]).update_all(value_solve: params[:authorization][:value_solve], situation: 2)
end
@employee = Employee.search_cpf(params[:search_employee_by_cpf])
@refinancing = Refinancing.new
Have no more errors, but dont save on my table authorization, and my query is wrong. This is my console:
Started GET "/refinancings/new?utf8=%E2%9C%93&search_employee_by_cpf11111&authorization%5Bcontract_ids%5D%5B%5D=11&authorization%5Bvalue_solve%5D%5B%5D=89888&authorization%5Bvalue_solve%5D%5B%5D=&authorization%5Bvalue_solve%5D%5B%5D=&commit=Reserve" for 127.0.0.1 at 2016-04-18 10:40:08 -0300
Processing by RefinancingsController#new as HTML
Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"1111111111", "authorization"=>{"contract_ids"=>["11"], "value_solve"=>["89888", "", ""]}, "commit"=>"Reserve"}
SQL (0.2ms) UPDATE "authorizations" SET "value_solve" = '---
- ''89888''
- ''''
- ''''
', "situation" = 2 WHERE "authorizations"."id" = 11
Employee Load (0.2ms) SELECT "employees".* FROM "employees" INNER JOIN "people" ON "people"."id" = "employees"."person_id" WHERE (people.cpf LIKE '%02849112321%') ORDER BY "employees"."id" ASC LIMIT 1
Person Load (0.1ms) SELECT "people".* FROM "people" WHERE "people"."id" = ? LIMIT 1 [["id", 1]]
Authorization Load (0.2ms) SELECT "authorizations".* FROM "authorizations" WHERE (contract_number in ('11'))
Rendered refinancings/new.html.erb within layouts/application (70.5ms)
Completed 200 OK in 119ms (Views: 85.2ms | ActiveRecord: 1.4ms)
How I said, I think that the error is because “authorizations”.id = 11. I haven’t id 11, id 11 equal contract_number. The id was to be 1.
Please, make more than 2 weeks that I try but nothing work =(
def new
if params[:authorization].present?
@selected_ids = params[:authorization][:contract_ids]
@authorizations = Authorization.where("contract_number in (?)",
@selected_ids)
Authorization.where(id:
params[:authorization][:contract_ids]).update_all(value_solve:
params[:authorization][:value_solve], situation: 2)
end
@employee = Employee.search_cpf(params[:search_employee_by_cpf])
@refinancing = Refinancing.new
Have no more errors, but dont save on my table authorization, and my query
is wrong. This is my console:
Started GET
"/refinancings/new?utf8=%E2%9C%93&search_employee_by_cpf11111&authorization%5Bcontract_ids%5D%5B%5D=11&authorization%5Bvalue_solve%5D%5B%5D=89888&authorization%5Bvalue_solve%5D%5B%5D=&authorization%5Bvalue_solve%5D%5B%5D=&commit=Reserve"
for 127.0.0.1 at 2016-04-18 10:40:08 -0300
Processing by RefinancingsController#new as HTML
Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"1111111111",
"authorization"=>{"contract_ids"=>["11"], "value_solve"=>["89888", "", ""]},
"commit"=>"Reserve"}
SQL (0.2ms) UPDATE "authorizations" SET "value_solve" = '---
- ''89888''
- ''''
- ''''
', "situation" = 2 WHERE "authorizations"."id" = 11
Employee Load (0.2ms) SELECT "employees".* FROM "employees" INNER JOIN
"people" ON "people"."id" = "employees"."person_id" WHERE (people.cpf LIKE
'%02849112321%') ORDER BY "employees"."id" ASC LIMIT 1
Person Load (0.1ms) SELECT "people".* FROM "people" WHERE "people"."id"
= ? LIMIT 1 [["id", 1]]
Authorization Load (0.2ms) SELECT "authorizations".* FROM
"authorizations" WHERE (contract_number in ('11'))
Rendered refinancings/new.html.erb within layouts/application (70.5ms)
Completed 200 OK in 119ms (Views: 85.2ms | ActiveRecord: 1.4ms)
How I said, I think that the error is because "authorizations".id = 11. I
haven't id 11, id 11 equal contract_number. The id was to be 1.
Please, make more than 2 weeks that I try but nothing work =(
You are making us work too hard by giving too much irrelevant detail.
Work out which line is not doing what you expect, then put
logger.info(...) statements before that line to display the values of
all relevant variables, then if it is still not working come back,
show us the line that is failing, the values of all the variables, and
the log showing what that line does (if relevant).
Whenever you have a problem you don’t understand, start by splitting the problem down into smaller parts, so the next thing is to split into two statements and check that the the first part before the update_all gives the correct record set.
authorisations = Authorisations.where(…)
And inspect the result.
You are passing an array for value_solve
"value_solve"=>["4343443", "", "", ""]]
you just want a single value.
Please quote the relevant parts of the previous message when replying
so we don't have to look back through old emails to find what you are
talking about. Thanks.
@selected_ids.zip(params[:authorization][:contract_number]).each do |id, value|
Authorization.where(contract_number: params[:authorization][:contract_number]).update_all(value_solve: params[:authorization][:value_solve], situation: 2)
end
Where @selected_ids = params[:authorization][:contract_number]
haven’t error, but in console my consult is wrong:
UPDATE “authorizations” SET “value_solve” = '—
‘’‘’
‘‘4345’’
‘‘454’’
‘’‘’
', “situation” = 2 WHERE “authorizations”.“contract_number” IN (‘22’, ‘33’)
And my column value_solve on Table Authorization is:
Is that an array? If so then when you say
update_all(value_solve: params[:authorization][:value_solve], situation: 2)
and params[:authorization][:value_solve] is an array, what do you
expect that to do?
If you look back at my early posts in this thread you will see I did
point out that your original code would not work with an array.
Apparently you ignored that.
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
Thanks!! After more then one week and very very very help, I finished it !! * - *
I didn’t understand… I just needed on my DB and finally worked!
What to use instead of upate_all so? I tried update_column and update_columns too, but nothing, because this I chose update_all same = (