Ich habe dieses Problem ... Ich muss meine Tabelle historische mit allen Berechtigungen IDs überprüfen, aktualisieren Sie die Spalte authorization_origin_id und legen Sie die Spalte refinancing_id mit der Refinanzierungs-ID erstellt. Beispiel: Ich überprüfte Genehmigungen IDs 2 und 3, so dass ich schaffen historische mit zwei Leitungen mit authorization_origin_id 2 und 3 und die Refinanzierung ID 1. Mein Code wird:Tabelle historisch mit allen Berechtigungen IDs geprüft Update-Spalte
meiner Sicht es:
<%= 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 %>
-Controller das ist:
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
Eigentlich ist mein Tisch historisch falsch, authorization_origin_id zu nehmen, nur die letzte (nur eine je = /) Wert geprüft und refinancing_id ist null
Ja, es ist die Antwort http://stackoverflow.com/questions/36874731/solve-query-sql-with-rails/ 36875135 # 36875135 –