请参考数字cpf上的复制值

时间:2016-04-07 13:25:32

标签: ruby-on-rails ruby ruby-on-rails-4 rails-4-2-1

我有一个搜索,当数字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])。全部

我尝试使用.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 -----------

1 个答案:

答案 0 :(得分: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

我的观点是我删除&lt;%= autorizacao.employee.person.name%&gt;并把&lt;%= employee.person.name%&gt;

这就行了!