Search code examples
ruby-on-railsruby-on-rails-4checkboxrails-4-2-1

Pass only checkboxes checked for other view


I have two views, the first is a table that show all authorizations, how I make for pass only the authorizations checked for other view?

This is first view: (all ok here)

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

My first and second controller:

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

In other view I want show just the checked:

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

Solution

  • I got it! It is My solution, created a repository for this, take a look on code:

    https://github.com/eltonsantos/playing_checkboxes