将ajax分页将是两次渲染页面

时间:2014-05-17 10:15:18

标签: ruby-on-rails ruby will-paginate

我在我的rails应用程序中使用ajax将分页。分页工作完美。但是在我点击下一页链接的一个页面中。它显示两次页面。但在其他页面中它工作正常。

这是我的index.js.erb:

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

我的index.html.erb就像:

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

服务器日志是:

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)

这是我的_jobs文件:

<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  %>

0 个答案:

没有答案