Why only save the last record in the table?

1

Well, here's a little help, please!

<%= form_tag(portabilizar_portabilidades_path, name: 'form', method: :get) do %>
      <table class="table table-condensed table-bordered table-hover">
        <thead>
          <tr>
            <th>&nbsp;</th>
            <th>Nº do contrato</th>
            <th>Nova parcela</th>
            <th>Verba proponente</th>
            <th>Ação</th>
          </tr>
        </thead>
        <tbody>
          <% @autorizacoes.each do |autorizacao| %>
            <tr>
              <td><%= radio_button_tag "autorizacao", autorizacao.id %></td>
              <td><%= autorizacao.numero_contrato %></td>
              <td>
                <input class="string required form-control" placeholder="Digite um valor" type="text" name="nova_parcela" id="portabilidade_nova_parcela">
              </td>
              <td>
                <%= collection_select( :portabilidade, :verba, Verba.all, :id, :descricao, {prompt: "Selecione a verba"}, {class: "form-control"} ) %>
              </td>
              <td><%= submit_tag "Portabilizar", :class => 'btn btn-primary btn-portabilizar', :disabled => true %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
    <% end %>

This is my view and my controller is this:

  def portabilizar

    @autorizacao = Autorizacao.find(params[:autorizacao])
    autorizacao_selecionada = params["autorizacao"].to_i
    @nova_parcela = params[:nova_parcela].to_i
    @verba_proponente = params[:portabilidade][:verba]

I just need that when clicking on my radiobutton, enter the value in the input, click the button and save the values. But this is only happening with the last record. The previous records are being saved as null, how to solve this? I do not know what I'm doing wrong.

    
asked by anonymous 17.05.2016 / 21:19

2 answers

1

I think it would be best if you did it like this:

  <table class="table table-condensed table-bordered table-hover">
    <thead>
      <tr>
        <th>&nbsp;</th>
        <th>Nova parcela</th>
        <th>Ação</th>
      </tr>
    </thead>
    <tbody>
      <% @autorizacoes.each do |autorizacao| %>
        <%= form_tag(portabilizar_portabilidades_path, method: :get) do |f| %>
          <tr>
            <td><%= radio_button_tag "autorizacao", autorizacao.id %></td>
            <td><%= autorizacao.numero_contrato %></td>
            <td>
              <%= text_field_tag "nova_parcela", '', class: "string required form-control", placeholder: "Digite um valor" %>
            </td>
            <td>
              <%= collection_select( :portabilidade, :verba, Verba.all, :id, :descricao, {prompt: "Selecione a verba"}, {class: "form-control"} ) %>
            </td>
            <td><%= submit_tag "Portabilizar", :class => 'btn btn-primary btn-portabilizar', :disabled => true %></td>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>
    
18.05.2016 / 18:22
0

Do so then:

<table class="table table-condensed table-bordered table-hover">
<thead>
  <tr>
    <th>&nbsp;</th>
    <th>Nova parcela</th>
    <th>Ação</th>
  </tr>
</thead>
<tbody>
  <% @autorizacoes.each do |autorizacao| %>
        <%= form_tag(portabilizar_portabilidades_path, method: :get) do |f| %>
    <tr>
      <td><%= radio_button_tag "radio_autorizacao", autorizacao.id %></td>
      <td><%= autorizacao.numero_contrato %></td>
      <td>
        <%= text_field_tag "nova_parcela", '', class: "string required form-control", placeholder: "Digite um valor" %>
      </td>
      <td>
        <%= collection_select( :portabilidade, :verba, Verba.all, :id, :descricao, {prompt: "Selecione a verba"}, {class: "form-control"} ) %>
      </td>
      <td>
        <%= hidden_field_tag "autorizacao", autorizacao.id %>
        <%= submit_tag "Portabilizar", :class => 'btn btn-primary btn-portabilizar', :disabled => true %>
      </td>
    </tr>
  <% end %>
</tbody>

    
18.05.2016 / 19:07