Rails 4: Can't get my dynamic table generation with JQuery get working -


i trying generate application produce table when search clicked seems not working.

what have tried followings.

controller:

def index @q = link.ransack(params[:q]) @links = @q.result(distinct: true) respond_to |format|   format.html # index.html.erb   format.js #index.js.erb end end 

index.html.erb:

<h1>listing links</h1> <!= implements search feature using gem "ransack" => <p><%= link_to 'advanced search', advanced_search_links_path %></p> <%= search_form_for @q, remote: true |f| %> <%= f.label :name_or_address_cont %> <%= f.search_field :name_or_address_cont %> <%= f.submit class: 'search_submit' %> <% end %>  <div id = 'result_table'>  </div>  <script type="text/javascript"> var ready; var result_table = $('#result_table');  ready = function(){   $('.search_submit').click(function(event){     $('#result_table').replacewith('<%= j render('table') %>'); }); };  $(document).ready(ready); $(document).on('page:load',ready);  </script> 

_table.html.erb:

<!= implements sorting attributes using gem "ransack" => <table> <thead id= 'result_head'>   <tr>     <th><%= sort_link @q, :name, "name" %></th>     <th><%= sort_link @q, :address, "address" %></th>     <th>availablity</th>     <th>like</th>     <th>dislike</th>     <th colspan="3"></th>   </tr> </thead> <tbody> <% @links.each |link| %>   <tr>     <h2>       <td><%= link_to link.name, link %><br></td>       <td><%= link_to link.address, link %><br></td>       <td><%= link_to link.bedroom, link %><br></td>       <td><%= link.get_upvotes.size %></td>       <td><%= link.get_downvotes.size %></td>     </h2>   </tr> </tbody> <% end %> </table> 

the issue having whenever click submit,

it generates table of every data in database

no matter letter search with.

i not sure if after first table generation, when click search search, if table regenerated or not.

i wonder if there missing ajax or what.

i appreciate helps.

please note using ransack implement search function.

thanks.

<%= j render('table') %> evaluated server-side, when make request. please read guide: http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -