Oscar_sgc
Oscar_sgc

Reputation: 350

Show/Hide render in Rails on button_to click

I'm trying to make something that must be really simple for most of you. I'm trying to hide a render/partial in some view in my rails app. I search 'bout how to do this, but i can't find any example or something that really works.

THis is my code

  <p id="notice"><%= notice %></p>
  <br>
  <CENTER><p>
  <h2>DATOS DEL LIBRO</h2>
  </p>
  <p>
  <b>Codigo Del Libro: </b>
  <%= @baptism_book.codigo %>
  </p>

  <p>
  <b>Numero De Libro:</b>
  <%= @baptism_book.numero %>
  </p>

  <p>
  <b>Cantidad de Paginas Del Libro:</b>
  <%= @baptism_book.paginas %>
  </p>

   <p>
   <b>Cantidad de Partidas por Pagina:</b>
   <%= @baptism_book.partidas_pagina %>
   </p>

   <p>
   <b>Parroquia:</b>
   <%= @baptism_book.parroquia %>
   </p>
   <br>
   <%= button_to 'Editar', edit_baptism_book_path(@baptism_book), :method => :get %>
   </CENTER> 
   <DIV Align=left>
   <%= button_to 'Volver', baptism_books_path, :method => :get %>

   </DIV>



   <h2>Partidas:</h2>

   <CENTER>
    <TABLE>
     <tr>
     <th>Tomo del libro</th>
      <th></th><th></th>
      <th>Numero de Partida</th>
      <th></th><th></th>
      <th>Pagina</th>
       <th></th><th></th>
       <th><%=link_to "Nombre", :sort => "Nombre" %></th>
        <th></th><th></th>
       <th>Fecha bautizo</th>
      <th></th><th></th>
       <th>Celebrante</th>
      <th></th><th></th>

      </tr>
     <% @baptism_book.baptism_items.each do |baptism_item| %>
     <tr>
     <td><center><%= baptism_item.tomo_libro %><center></td>
     <td></td><td></td>
     <td><center><%= baptism_item.numero %></center></td>
     <td></td><td></td>
     <td><center><%= baptism_item.pagina %></center></td>
     <td></td><td></td>
     <td><center><%= baptism_item.nombre %></center></td>
     <td></td><td></td>
     <td><center><%= baptism_item.fecha_bautizo %></center></td>
     <td></td><td></td>
    <td><center><%= baptism_item.celebrante %></center></td>
    <td></td><td></td>
   <td><%= link_to 'Ver', baptism_item %></td>
   <td><%= link_to 'Editar', edit_baptism_item_path(baptism_item) %></td>

   </tr>
   <% end %>
   </table>
   </CENTER>

   <br>
   <br>



   <h2>Agregar Partida:</h2>
   <%= render "baptism_items/form" %>

As you can see in the last line there's a render tag (<%= render "baptism_items/form" %> )i wish that render could hide/show when i click some link or button or something.

Please help me with that?

Upvotes: 0

Views: 2541

Answers (2)

Piotr Kruczek
Piotr Kruczek

Reputation: 2390

If you are sure you don't need this partial in one particular view you should define a variable in your controller to make sure this part doesn't render in DOM at all, not just be hidden with javascript, for example:

render_partial? = false

Then in your view:

<%= render "baptism_items/form" if render_partial? %>

Upvotes: 0

agastalver
agastalver

Reputation: 1056

You could put a div that cover your render.

<h2>Agregar Partida:</h2>
<div id="mydivtohide">
  <%= render "baptism_items/form" %>
</div>

This way you only have to hide the div.

Upvotes: 2

Related Questions