12

我正在为管理面板使用活动管理员。在用户展示页面上,我需要展示他的朋友。我有两个模型用户和朋友。

我想在“与面板的友谊”即user.friends块中添加分页。

如何在一个面板上添加分页?这是我正在使用的代码。

show do
  attributes_table  do
    row("Photo") { |user| image_tag(user.facebook_photo_url) }
    rows :name, :sex,:city
  end

  panel 'Friendship with' do
    table_for user.friends do
      column "" do |friend|
        (link_to image_tag(friend.facebook_photo_url('small')), admin_friend_path(friend)) + "       ".html_safe +  (link_to friend.name, admin_user_path(friend))
      end

    end
  end  

  active_admin_comments
end

Friend 模型实际上是 Facebook 朋友,所以我不能在 User 模型上使用自引用连接(所以不要说使用一个模型而不是两个模型),并且我在同一页面上有一些其他面板。我需要确保每个面板都有自己的分页参数名称,这样它们就不会相互冲突。

4

1 回答 1

26

前段时间我写了这样的东西来为一页上的多个表添加分页。通过更改 paginated_collection 参数,您可以拥有多个表。

我希望这段代码可以提供帮助。

users = User.by_customer(customer.customer_id) #by_customer is scope
panel 'Users' do
  paginated_collection(users.page(params[:users_page]).per(15), param_name: 'users_page') do
    table_for(collection) do |cr|
      column(I18n.t("cr.start")) { |cr| I18n.l cr.start, format: :raw }
        #other columns...
     end
   end
 end
于 2012-12-27T14:32:28.090 回答