0

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  %>
9
  • is index.js.erb getting rendered twice.. update server log and more relevant code if possible
    – Dave
    May 17, 2014 at 10:19
  • the _jobs.html.erb is rendered twice.
    – Randhir
    May 17, 2014 at 10:20
  • updated your server log and view file code with partial
    – Dave
    May 17, 2014 at 10:20
  • did you inspect with firebug and check if your ajax is getting fired twice. Also update your question with code in _job partial.
    – Dave
    May 17, 2014 at 10:26
  • Yes I checked the firebug but the ajax call is not twice ?
    – Randhir
    May 17, 2014 at 10:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.