0

我的应用程序几乎完成了,现在我正在搞乱化妆品,并决定做一些分页。will_paginate 对我来说没有用,所以我尝试了 Kanimari,它在不使用 Ajax 的时候就可以工作。

我的问题是我的页面有 2 个彼此不同的分页索引,因此使用不同的集合。

使用分页标签上的标签“:remote => true”它不起作用,在我看来,它试图在只点击一个分页时填充两个分页。

我的文件如下

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>

页面控制器'

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

我在 firebug 的控制台上得到的错误是:

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

控制台的日志:

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)

当我点击它时,网址也不会改变......

有什么想法吗?

4

1 回答 1

0

您是否有理由将“.to_s”附加到您的 javascript 调用中?尝试改变:

$("#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) %>")

$("#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') %>")
于 2012-08-25T04:25:01.097 回答