How to pass parameter for validation / treatment in the RUBY view

0

I have a great doubt, I accept tips if they see a better option to do what I want. I have a layout that links to two items in the same view > >

<ul class="nav nav-second-level">
  <li>
   <%= link_to backoffice_pedidos_path do %>
     Abertos
   <% end %>
  </li>
  <li>
    <%= link_to backoffice_pedidos_path do %>
      Finalizados
    <% end %>
   </li>
 </ul>

I want to treat the contents of my select in the view, if it clicks OPEN, it loads the index with a partial _options and if it clicks Finished it loads the index but with another partial _finished. Is there any way to pass some parameter in the link_to so that in the view I can handle it to send to the correct partial? Or any tips on how to stay?

index > >

                    <thead>
                    <tr>
                        <th>Pedido</th>
                        <th>Status</th>
                        <th>Data/Hora </th>
                        <th>Produtos </th>                    
                        <th> </th>
                    </tr>
                </thead>
                <tbody> 
                  <% if ??
                  <%= render partial: "backoffice/pedidos/abertos" %>
                  else ??
                  <%= render partial: "backoffice/pedidos/finalizados" %>
                  <% end %>
                </tbody>

partial open > >

           <% @pedidos_aguardando.each do |pedido| %>
        <tr> 
          <td><%=pedido.id%></td>
          <td><%=pedido.status%></td>
          <td><%=pedido.created_at%></td>
          <!--<th><%=pedido.produtos.first.produto %></th>-->
          <td><%=pedido.produtos.pluck (:produto)%></td>
          <td width="50px">
              <%= link_to edit_backoffice_pedido_path(pedido), class:"btn btn-primary btn-circle" do %>
                <i class="fa fa-edit"></i>
              <% end %>
          </td>
        </tr>
      <% end %>

Closed Partials

           <% @pedidos_finalizados.each do |pedido| %>
        <tr> 
          <td><%=pedido.id%></td>
          <td><%=pedido.status%></td>
          <td><%=pedido.created_at%></td>
          <!--<th><%=pedido.produtos.first.produto %></th>-->
          <td><%=pedido.produtos.pluck (:produto)%></td>
          <td width="50px">
              <%= link_to edit_backoffice_pedido_path(pedido), class:"btn btn-primary btn-circle" do %>
                <i class="fa fa-edit"></i>
              <% end %>
          </td>
        </tr>
      <% end %>

Controller

def index
@pedidos_aguardando = Pedido.waiting
@pedidos_finalizados = Pedido.ok
 end

Model

class Pedido < ActiveRecord::Base
has_many :produtos

scope :waiting, -> { where(status: 1) }
scope :ok, -> { where(status: 2) }
end

Thank you !!

    
asked by anonymous 26.08.2017 / 22:40

1 answer

0

You put the link in the link:

link_to backoffice_pedidos_path (type: 'open')

This will give you the controller access to a params [: type]

put this in a variable, remembering to treat the case of the first load, where this parameter will be empty ex:

@tipo = params[:tipo] || 'abertos'

Use the name of the partials in the parameters, so in the view you do:

<%= render partial: "backoffice/pedidos/#{@tipo}" %>
    
28.08.2017 / 19:06