我有这个问题:
我有一个控制器:
def index
if params[:search_employee_by_cpf].present?
@employees = Employee.search_cpf(params[:search_employee_by_cpf]).all
@authorizations = Authorization.search_employee_by_cpf(params[:search_employee_by_cpf]).all
end
end
型号授权:
scope :search_employee_by_cpf, -> (cpf) { Authorization.joins("INNER JOIN employees ON employees.id = authorizations.employee_id INNER JOIN people ON employees.person_id = people.id").where("people.cpf LIKE ?", "%#{cpf}%") }
和模范员工:
scope :search_cpf, -> (cpf) { joins(:person).where("people.cpf LIKE ?", "%#{cpf}%") }
我需要两个注册表/矩阵,并且我需要为每个注册表/矩阵显示授权。实际上,显示每个寄存器的所有授权,这是错误的!我只想显示各个寄存器的授权。这个怎么做?
更新 - - - - - - - - - - - - -
这是我对演出授权负责的部分观点
<% @authorizations.each do |authorization| %>
<tr>
<td><%= check_box_tag 'authorization[contract_ids][]', authorization.contract_number %></td>
<td><%= authorization.contract_number %></td>
<td><%= number_to_currency authorization.parcel_value %></td>
<td><%= authorization.qtd_parcel %></td>
<td><%= number_to_currency authorization.total_value %></td>
<td>
<%= simple_form_for('/', remote: true) do |f| %>
<%= f.input :value_solve, label: false, placeholder: "Digit a value" %>
<%= f.submit 'Gravar valor' %>
<% end %>
</td>
</tr>
<% end %>
更新 2 -------------
def new
if params[:authorization]
@selected_ids = params[:authorization][:contract_ids]
@authorizations = Authorization.where("contract_number in (?)", @selected_ids)
end
@employee = Employee.search_cpf(params[:search_employee_by_cpf])
@refinancing = Refinancing.new
end
new.html.erb(检查并单击按钮转到新的)
<table class="table table-condensed table-bordered">
<tr>
<td>Name:</td>
<td><%= @employee.person.name %></td>
</tr>
<tr>
<td>CPF:</td>
<td><%= @employee.person.cpf %></td>
</tr>
</table>