Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用rails解决查询sql_Sql_Ruby On Rails_Ruby On Rails 4_Sql Update_Where Clause - Fatal编程技术网

使用rails解决查询sql

使用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

当我创建历史性的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.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