0

我有两个视图,第一个是显示所有授权的表,我如何只通过检查其他视图的授权?

这是第一个视图:(这里都可以)

(...)
 <% @authorizations.each do |authorization| %>
      <tr>
        <td><%= check_box_tag 'authorization_marked' %></td>
(...)
<%= f.button :submit, "To Reserve" %>

我的第一个和第二个控制器:

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
    else
      @authorizations = []
    end
  end

  # GET /refinancings/new
  def new
    @employee = Employee.search_cpf(params[:search_employee_by_cpf])
    @authorizations.authorization_marked = true # PROBLEM HERE
    @refinancing = Refinancing.new
  end

在其他视图中,我只想显示选中的:

  <h3>Reserved value</h3>
  <table class="table table-condensed table-bordered table-striped">
    <thead>
      <th>Contract number</th>
      <th>Parcel value X Quantity of Parcels</th>
    </thead>
    <% @authorizations.each do |authorization| %>
      <tbody>
        <tr>
          <td><%= authorization.contract_number %></td>
          <td><%= number_to_currency authorization.parcel_value %> x <%= authorization.qtd_parcel %></td>
        </tr>
      </tbody>
    <% end %>
  </table>
4

2 回答 2

1

因此,您的第一个表单需要捕获要传递给第二个视图的所有行的 ID 号。在您的第二个操作中,您需要捕获这些参数,并制作您希望第二个视图加载的对象的集合。

当您发布第一个表单时,请仔细查看正在传递的数据,这是您必须使用的数据来创建您想要的下一个集合。

于 2016-04-11T03:41:47.987 回答
0

我知道了!这是我的解决方案,为此创建了一个存储库,看看代码:

https://github.com/eltonsantos/playing_checkboxes

于 2016-04-12T23:33:38.660 回答