0

我有一个搜索,当数字一个 CPF 显示所有结果。好的,但我需要这样显示:(只是一个人和它拥有的合同数量)*我的代码是葡萄牙语,抱歉

Name
Registry
CPF
   Contract 1 ---- Show all contracts
   Contract 2   --------
   Contract 3 -----------

但目前是这样的:(根据合同金额相同的值)

Name
Registry
CPF
   Contract 1 ---- Show all contracts
   Contract 2   --------
   Contract 3 -----------

Name
Registry
CPF
   Contract 1 ---- Show all contracts
   Contract 2   --------
   Contract 3 -----------

Name
Registry
CPF
   Contract 1 ---- Show all contracts
   Contract 2   --------
   Contract 3 -----------

它正在复制价值......因为合同的编号

我的看法是这样的:

<% if params[:pesquisa_func_cpf].present? %>
  <h4><b>Resultados</b></h4>
  <% @autorizacoes.each do |autorizacao| %>
    <table class="table table-condensed">
      <tr>
        <th>Name</th>
        <td><%= autorizacao.employee.person.name %></td>
      </tr>
      <tr>
        <th>Registry</th>
        <td><%= autorizacao.employee.registry %></td>
      </tr>
      <tr>
        <th>CPF</th>
        <td><%= autorizacao.employee.person.cpf %></td>
      </tr>
    </table>
    <hr />
    <table class="table table-condensed table-bordered">
      <th>Contract number</th>
      <% @autorizacoes.each do |autorizacao| %>
        <td><%= autorizacao.number_contract %></td>
      <% end %>
    </table>

  <% end %>
<% end%>

这是我的控制器:

如果 params[:pesquisa_func_cpf].present?@autorizacoes = Autorizacao.pesquisa_func_cpf(params[:pesquisa_func_cpf]).all

我尝试使用 .distinct 而不是 .all,但不起作用:(

我的咨询(我使用 oracle)是:

select * from autorizacoes INNER JOIN employers ON employers.id = autorizacoes.employer_id
                           INNER JOIN people ON employers.person_id = people.id
                           WHERE people.cpf  LIKE '111.111.111-11'

根据我的示例,它返回 3 个结果。请,如何让这个结构离开:

Name
Registry
CPF
   Contract 1 ---- Show all contracts
   Contract 2   --------
   Contract 3 -----------
4

1 回答 1

0

我知道了!在我的控制器中,我只是这样:

if params[:pesquisa_func_cpf].present?
      @employers = Employee.pesquisa_cpf(params[:pesquisa_func_cpf]).all
      @autorizacoes = Autorizacao.pesquisa_func_cpf(params[:pesquisa_func_cpf]).all

我的观点是删除 <%= autorizacao.employee.person.name %> 并放入 <%= employee.person.name %>

就是这个并且有效!

于 2016-04-07T14:56:45.333 回答