使用rails解决查询sql
当我创建历史性的do it时,我需要:使用rails解决查询sql,sql,ruby-on-rails,ruby-on-rails-4,sql-update,where-clause,Sql,Ruby On Rails,Ruby On Rails 4,Sql Update,Where Clause,当我创建历史性的do it时,我需要: Table historic id authorization_origin_id 1 2 2 3 你在下面的图片中看到了什么 这是我的新.html.erb <%= simple_form_for(@refinancing) do |f| %> <div class="form-inputs"> <%= f.hidden_field :employee_id, value: @employee.firs
Table historic
id authorization_origin_id
1 2
2 3
你在下面的图片中看到了什么
这是我的新.html.erb
<%= simple_form_for(@refinancing) do |f| %>
<div class="form-inputs">
<%= f.hidden_field :employee_id, value: @employee.first.id %>
<%= 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 %>
目前,出现以下错误:
授权_origin _id为空,请告诉我如何获取此信息?在您的控制器中,您正在创建没有任何参数的
historiccrefinancing
historiccrefinancing.create
创建一个具有空授权\来源\ id、再融资\ id和授权\新\ id的条目
下面的代码不执行任何操作,它尝试查找具有授权\u来源\u id==auth\u id
的historiccrefinancing
s,然后将该字段更新为相同的auth\u id
值
@historic\u retrofinance=historiccrefinancing.where(授权来源:auth\u id)。更新所有(授权来源:auth\u id)
现在还不清楚您想在控制器的这一部分中做什么,但我怀疑您想将这两行压缩为historiccrefinancing.create(authorization\u origin\u id:auth\u id)
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.where(authorization_origin_id: auth_id).update_all(authorization_origin_id: auth_id)
end
end
@employee = Employee.search_cpf(params[:search_employee_by_cpf])
@refinancing = Refinancing.new
end