Will ajax will pagination is rendergin the page twice

痴心易碎 提交于 2020-01-14 06:06:09

问题


I am using ajax will pagination in my rails application. The pagination is working perfectly. But in one page when I click on next page link. It showing the page twice. But in other pages it working fine.

Here is my index.js.erb:

$('.sort_paginate_ajax').html("<%= escape_javascript(render("jobs"))%>");    
$(".tablesorter").tablesorter();

And my index.html.erb is like:

<div class="sort_paginate_ajax"><%= render 'jobs' %></div>

The server log is:

Started GET "/jobs?page=2&_=1400322005679" for 127.0.0.1 at 2014-05-17 15:50:12 +0530
Processing by JobsController#index as JS
  Parameters: {"page"=>"2", "_"=>"1400322005679"}
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
  Job Load (0.5ms)  SELECT "jobs".* FROM "jobs" LIMIT 2 OFFSET 2
   (0.3ms)  SELECT COUNT(*) FROM "jobs"
  Location Load (0.4ms)  SELECT "locations".* FROM "locations" WHERE "locations"."id" = 2
  Client Load (0.4ms)  SELECT "clients".* FROM "clients" WHERE "clients"."id" = 2
  Location Load (0.5ms)  SELECT "locations".* FROM "locations" WHERE "locations"."id" = 1
  Client Load (0.4ms)  SELECT "clients".* FROM "clients" WHERE "clients"."id" = 1
DEPRECATION WARNING: link_to_function is deprecated and will be removed from Rails 4.1. We recommend using Unobtrusive JavaScript instead. See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript. (called from link at /var/www/selectcom/app/helpers/will_paginate_helper.rb:16)
DEPRECATION WARNING: link_to_function is deprecated and will be removed from Rails 4.1. We recommend using Unobtrusive JavaScript instead. See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript. (called from link at /var/www/selectcom/app/helpers/will_paginate_helper.rb:16)
DEPRECATION WARNING: link_to_function is deprecated and will be removed from Rails 4.1. We recommend using Unobtrusive JavaScript instead. See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript. (called from link at /var/www/selectcom/app/helpers/will_paginate_helper.rb:16)
DEPRECATION WARNING: link_to_function is deprecated and will be removed from Rails 4.1. We recommend using Unobtrusive JavaScript instead. See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript. (called from link at /var/www/selectcom/app/helpers/will_paginate_helper.rb:16)
  Rendered jobs/_jobs.html.erb (15.3ms)
  Rendered jobs/index.js.erb (18.7ms)
Completed 200 OK in 28ms (Views: 22.5ms | ActiveRecord: 3.0ms)

Here is my _jobs file:

<tbody>

    <% @jobs.each do |job| %>

      <tr>

        <td><%= job.created_at %></td>

        <% @locations = Location.where(:id => job.location_id) %>

          <% if(@locations.length != 0) %>

            <% @locations.each do |location| %>

               <td><%= location.Site %></td>

               <td><%= location.City.capitalize %>/<%= location.State.capitalize %></td>

            <% end %>

          <% end %>

        <% @clientlist = Client.where(:id => job.client_id) %> 

           <% if(@clientlist.length != 0) %>

             <% @clientlist.each do |client| %>

               <td><%= client.ClientName.capitalize %></td>

             <% end %>

           <% end %>

        <td>TODO</td>

        <td>TODO</td>

        <td><%= job.SalesOrder %></td>

        <td>TODO</td> 

        <td><%= link_to '', edit_job_path(job),:class =>'edit_icon' %><%= link_to 'X', job, :class=>'rmv-fld', method: :delete, data: { confirm: 'Are you sure?' } %></td>

      </tr>

    <% end %>

  </tbody>

</table>

<% if @jobs.length!=0 %>

    <div class="me-tdy">
           <table width="100%" border="0" style="border:none !important" class="table_clr2 table">

            <tbody>
<tr>
            <td width="90%" align="left" style="border:none"><h2 style="padding:0;" class="job_heading">JOBS</h2></td>

            <td width="10%" style="border:none">

             <div class="arrow_bx">

             <%= ajax_will_paginate @jobs, :params => { :my_excluded_param => nil } %>

             </div></td>

          </tr>

      </tbody></table>

        </div>

</div><% else  %>

来源:https://stackoverflow.com/questions/23710109/will-ajax-will-pagination-is-rendergin-the-page-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!