0

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>
Elton Santos
  • 571
  • 6
  • 32
  • This part: `how I make for pass only the authorizations checked for other view?`, I did not understand at all. – Matt C Apr 11 '16 at 02:02
  • More context is needed. Can you show the whole form section for the first view? And also the controller action rendering the HTML in your third block of code? – Anthony E Apr 11 '16 at 02:02
  • @AnthonyE - is my repository: https://github.com/eltonsantos/playing_checkboxes – Elton Santos Apr 11 '16 at 02:08
  • @MatthewCliatt - https://github.com/eltonsantos/playing_checkboxes – Elton Santos Apr 11 '16 at 02:08
  • I have four authorizations, I check just two, click in submit. In other view I will show just this two authorizations checked, just this that I want. – Elton Santos Apr 11 '16 at 02:27

2 Answers2

1

So your first form needs to capture the id numbers of all the rows you want to pass to the second view. In your second action, you need to capture those parameters, and make a collection of the objects you want the second view to load.

Take a very close look at what data is being passed when you post the first form, that's the data you have to use to create the next collection you want.

tkz79
  • 95
  • 10
  • Have some example on git ot in another place? I 'm trying, but nothing yet, I make a example on my git: github.com/eltonsantos/playing_checkboxes – Elton Santos Apr 11 '16 at 11:54
  • <%= check_box_tag 'authorization_ids[]', authorization.id %> this is my checkbox, it's ok? – Elton Santos Apr 11 '16 at 14:03
0

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

https://github.com/eltonsantos/playing_checkboxes

Elton Santos
  • 571
  • 6
  • 32