使用此代码:
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
没有更多的错误,好的,但是不要保存在我的表中授权,因为id是错误的。看看我的控制台:
Started GET "/refinancings/new?utf8=%E2%9C%93&search_employee_by_cpf=02849112321&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)
"authorizations"."id" = 11,但我没有 id 11 的授权,应该是 id 1。我该怎么办?请 : (
更新 - - - - - - - - - - - - - - - -
这是我的观点 index.html.erb。我在输入 value_solve 上标记了复选框和数字一些值,然后单击 Reserve
<% if params[:search_employee_by_cpf].present? %>
<h4><b>Results</b></h4>
<%= form_tag(new_refinancing_path, name: 'form', method: :get) do %>
<%= hidden_field_tag 'search_employee_by_cpf', params[:search_employee_by_cpf] %>
<% @employees.each do |employee| %>
<table class="table table-condensed">
<tr>
<th>Name</th>
<td><%= employee.person.name %></td>
</tr>
<tr>
<th>Register</th>
<td><%= employee.register %></td>
</tr>
<tr>
<th>CPF</th>
<td><%= employee.person.cpf %></td>
</tr>
</table>
<hr />
<table class="table table-condensed table-bordered table-hover">
<thead>
<th> </th>
<th>Contract number</th>
<th>Total Value</th>
<th>Value to Solve</th>
</thead>
<tbody>
<% employee.authorizations.each do |authorization| %>
<tr>
<td><%= check_box_tag 'authorization[contract_ids][]', authorization.contract_number %></td>
<td><%= authorization.contract_number %></td>
<td><%= authorization.total_value %></td>
<td>
<input class="string required" placeholder="Digit a value" type="text" name="authorization[value_solve][]" id="authorization_value_solve">
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<%= submit_tag "Reserve %>
<% end %>
<% end %>
表单索引的控制器很简单并且可以工作,就是这样:
def index
if params[:search_employee_by_cpf].present?
@employees = Employee.search_cpf(params[:search_employee_by_cpf]).includes(:authorizations)
Authorization.search_employee_by_cpf(params[:search_employee_by_cpf]).all
else
@authorizations = []
end
end
单击保留后,选中复选框并数字化我的控制台是这样的,我怎么说:
Started GET "/refinancings/new?utf8=%E2%9C%93&search_employee_by_cpf=02849112321&authorization%5Bcontract_ids%5D%5B%5D=11&authorization%5Bvalue_solve%5D%5B%5D=777777&authorization%5Bvalue_solve%5D%5B%5D=&authorization%5Bvalue_solve%5D%5B%5D=&commit=Reserve" for 127.0.0.1 at 2016-04-18 16:08:37 -0300
Processing by RefinancingsController#new as HTML
Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"02849112321", "authorization"=>{"contract_ids"=>["11"], "value_solve"=>["777777", "", ""]}, "commit"=>"Reserve"}
SQL (0.2ms) UPDATE "authorizations" SET "value_solve" = '---
- ''777777''
- ''''
- ''''
', "situation" = 2 WHERE "authorizations"."id" = 11
sdsds