jquery-datatables-rails not showing up after a link_to but does other times -


i trying jquery-data-table in rails 4.0 (ruby 2.2) work. in strange way does. if goto index view in groups controller (snippet):

<%- model_class = group -%> <div class="page-header">   <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1> </div>  <!-- table class="table table-striped"  id="groups" --> <table class="display"  id="groups">   <thead>     <tr>       <th><%= model_class.human_attribute_name(:id) %></th>       <th><%= model_class.human_attribute_name(:name) %></th>       <th><%= model_class.human_attribute_name(:address) %></th>       <th><%= model_class.human_attribute_name(:city) %></th>       <th><%= model_class.human_attribute_name(:phone) %></th>       etc.. 

i have required javascript jquery data tables in groups.js file

$(document).ready( function () {     $("#groups").datatable({paging:true,                              pagingtype: 'full_numbers'     }); }); 

and works, if goto url: `localhost:3000/groups'

it works, see data table, empty, or data whichever database state works , searching. problem if goto , create new group... , save it, goes show, , click goto index, shows table if no jquery-data-tables there. headings different, no pagination, no search, nothing. if click above url , press enter loads fine again.

same thing if go home page groups controller without typing url box using link_to bootstrap3 button here:(from homepage index html)

<%= link_to groups_path %>                  <button type="button" class="btn btn-default btn-lg">                     <span class="glyphicon glyphicon-user" aria-hidden="true" ></span> group                 </button>             <% end %> 

then works, takes groups , shows data in table not jquery datatable. making me go bonkers no idea why typing in url bar , going there works when link_to or 'back' on show form (groups_path) isn't working.

got same issue you, , solved following step.

change 1st line in "groups.js" file to

$(document).on "page:change", -> 

the information from: http://guides.rubyonrails.org/working_with_javascript_in_rails.html#page-change-events


Popular posts from this blog