我有这个问题...我需要保存我的表历史记录并检查所有授权ID,更新列authorization_origin_id并设置列refinancing_id并创建再融资ID。示例:我检查了授权ID ids 2和3,因此我使用authorization_origin_id 2和3创建两行历史记录,再融资ID为1.我的代码:
我的观点:
<%= simple_form_for(@refinancing) do |f| %>
<div class="form-inputs">
<%= f.hidden_field :employee_id, value: @employee.first.id %>
<%= f.hidden_field :authorization, value: @authorization %>
<%= f.input :contract_number %>
</div>
<h3>Reserved value</h3>
<table class="table table-condensed table-bordered table-striped">
<thead>
<th>Authorization id</th>
<th>Contract number</th>
</thead>
<% @authorizations.each do |authorization| %>
<tbody>
<tr>
<td><%= authorization.id %></td>
<td><%= authorization.contract_number %></td>
</tr>
</tbody>
<% end %>
</table>
<div class="form-actions">
<%= f.button :submit, "To Reserve" %>
</div>
<% end %>
控制器就是这样:
def new
if params[:authorization].present?
@selected_ids = params[:authorization][:contract_number]
@authorizations = Authorization.where("contract_number in (?)", @selected_ids)
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
@authorizations.ids.each do |auth_id|
@historic_refinancing = HistoricRefinancing.create
@historic_refinancing = HistoricRefinancing.update_all(authorization_origin_id: auth_id)
end
end
@employee = Employee.search_cpf(params[:search_employee_by_cpf])
@refinancing = Refinancing.new
end
实际上我的表历史是错误的,authorization_origin_id采取,只检查了最后一个(只有一个= /)值并且refinancing_id为空
答案 0 :(得分:0)
答案是:
@historic_refinancing = HistoricRefinancing.where(authorization_origin_id: auth_id).update_all(authorization_origin_id: auth_id)
或只是这个
@historic_refinancing = HistoricRefinancing.create(authorization_origin_id: auth_id)