** If I move the button here, it works perfectly ** <" /> ** If I move the button here, it works perfectly ** <" /> ** If I move the button here, it works perfectly ** <"/>

Button_tag not working inside table in Rails

372 views Asked by At

I have the following button_tag inside a form in a table:

<div class="table-responsive tableBG">
** If I move the button here, it works perfectly **
  <table class="table table-striped table-sm table-mini">
    <thead class="thead">
      <tr>
        <th>...</th>
      </tr>
    </thead>
    <tbody>
      <tr>...</tr>
      ...
      <%= form_for article, :html => {:class => 'toggle'} do |f| %>
        <%= f.hidden_field :disable, value: true %>
        <%= button_tag type: 'submit', class: "btn-mini" do %>
          <i class="fa fa-eye-slash" aria-hidden="true"></i>
        <% end %>
      <% end %>
     ...
    </tbody>
  </table>
</div>

My index.js.erb (called every 10 seconds, renders the table above):

$("#todaysarticles").html("<%= escape_javascript(render(:partial => 'todaysarticles')) %>")

This button works perfectly outside the table (in the first div as commented in the code), but it does not work at all inside the table after an ajax call (partial reload).

I have several link_to's that work inside the table, even after the ajax call, but none of the button_tags for the forms work at all.

1

There are 1 answers

0
Dark Knight On BEST ANSWER

Fixed this issue by switching all my button_tag's to link_to's by following this great guide:

http://buckybits.blogspot.com/2011/09/simple-ajax-property-toggle-in-rails-30.html