0

My app is almost complete, now I am messing with cosmetics, and decided to do some pagination. will_paginate for me did not work, so I tried Kanimari, which is working whenever is not using Ajax.

My problem is I have a page with 2 pagination indexes different from each other, and hence using different collections.

With the tag ":remote => true" on the paginate tag it does not work, it seems to me that it is trying to populate both of the paginations when clicking in only one.

My files are as follows

feed.js.erb

$("#myItems").html("<%= escape_javascript(render partial: 'shared/feed_item', collection: @feed_items) %>");
$("#myBids").html("<%= escape_javascript(render partial: 'shared/feed_bid_item', collection: @feed_bids) %>");
$("#paginatorItem").html("<%= escape_javascript(paginate(@feed_items, :remote => true, :param_name => 'feed_items_page').to_s) %>")
$("#paginatorBids").html("<%= escape_javascript(paginate(@feed_bids, :remote => true, :param_name => 'feed_bids_page').to_s) %>")

feed.html.erb

<div class="row span8">
  <h3>Latest Bidded Items</h3>
  <div id="paginatorBid"><%= paginate @feed_bids, :remote => true, :param_name => :feed_bids_page  %> </div>
  <% if @feed_bids.any? %>
      <div id ="myBids" class="microposts">
        <%= render partial: 'shared/feed_bid_item', collection: @feed_bids %>
      </div>
  <% end %>
</div>
<div class="row span8">
  <h3>My Items</h3>
  <div id="paginatorItem"> <%= paginate @feed_items, :remote => true, :param_name => :feed_items_page %>  </div>
  <% if @feed_items.any? %>
      <div id="myItems" class="microposts">
        <%= render partial: 'shared/feed_item', collection: @feed_items %>
      </div>
  <% end %>
  <div id="paginatorItem"> <%= paginate @feed_items, :remote => true, :param_name => :feed_items_page %>  </div>
</div>

Controller for the pages'

class StaticPagesController < ApplicationController
  def home
    if signed_in?
      @items  = current_user.items.build
      @feed_items = current_user.feed.page(params[:feed_items_page]).per(10)
      @feed_bids = current_user.bid_feed.page(params[:feed_bids_page]).per(2)
    end
  end

  def help
  end

  def about
  end

  def contact
  end

  private

end

The error that I get, on the console for firebug is:

GET http://localhost:3000/?feed_bids_page=2 500 (Internal Server Error) jquery.js:8241
jQuery.ajaxTransport.send jquery.js:8241
jQuery.extend.ajax jquery.js:7720
$.rails.rails.ajax jquery_ujs.js:99
$.rails.rails.handleRemote jquery_ujs.js:158
(anonymous function) jquery_ujs.js:309
jQuery.event.dispatch jquery.js:3333
jQuery.event.add.elemData.handle.eventHandle jquery.js:2942

The log for the console:

Started GET "/?feed_bids_page=2" for 127.0.0.1 at 2012-08-24 15:38:32 -0300
Processing by StaticPagesController#home as JS
  Parameters: {"feed_bids_page"=>"2"}
  User Load (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'mb0cXIVY5QJQEoQt0dr7Zg' LIMIT 1
   (0.0ms)  SELECT COUNT(*) FROM "items" WHERE "items"."user_id" = 1
  Rendered shared/_user_info.html.erb (3.0ms)
  Rendered shared/_error_messages.html.erb (1.0ms)
  Rendered shared/_item_form.html.erb (4.0ms)
  Rendered shared/_feed_item.html.erb (3.0ms)
  Rendered shared/_feed.js.erb (24.0ms)
  Rendered static_pages/home.html.erb (37.0ms)
Completed 500 Internal Server Error in 2080ms

ActionView::Template::Error (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id):
    1: <li id="<%= feed_item.id %>" class="row">
    2:    <span class="user span6">Item Name:  <%= link_to feed_item.item_name, feed_item %></span>
    3:   <% if current_user?(feed_item.user) %>
    4:       <%= link_to "delete", feed_item, method: :delete,
  app/views/shared/_feed_item.html.erb:1:in `_app_views_shared__feed_item_html_erb___529660946_51689088'
  app/views/shared/_feed.js.erb:1:in `_app_views_shared__feed_js_erb___248436956_49382712'
  app/views/static_pages/home.html.erb:12:in `_app_views_static_pages_home_html_erb___289375805_49187496'


  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (4.0ms)
  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (23.0ms)

Also the url does not change when I click on it...

Any thoughts?

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
Vinchbr
  • 49
  • 4

1 Answers1

0

Is there a reason you are appending ".to_s" to your javascript calls? Try changing:

$("#paginatorItem").html("<%= escape_javascript(paginate(@feed_items, :remote => true, :param_name => 'feed_items_page').to_s) %>")
$("#paginatorBids").html("<%= escape_javascript(paginate(@feed_bids, :remote => true, :param_name => 'feed_bids_page').to_s) %>")

to

$("#paginatorItem").html("<%= j paginate(@feed_items, :remote => true, :param_name => 'feed_items_page') %>")
$("#paginatorBids").html("<%= j paginate(@feed_bids, :remote => true, :param_name => 'feed_bids_page') %>")
neon
  • 2,811
  • 6
  • 30
  • 44