Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination for panel in active admin

I am using active admin for admin panel. On User show page I need to show his friends. I have two models User and Friend.

I want add pagination in the "friendship with panel" ie user.friends block.

How can I add pagination on one panel? Here is the code that I am using.

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

The Friend model is actually Facebook friends so I can't use self-referential joins on User model (so don't say use one model instead of two) and I have some other panels on the same page. I need to make sure every panel has their own pagination param name so that they don't conflict with each other.

like image 304
Mohit Jain Avatar asked Dec 24 '12 06:12

Mohit Jain


1 Answers

Some time ago I wrote something like this to add pagination to multiple tables on one page. You can have multiple tables, by changing paginated_collection parameters.

I hope this code can help.

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
like image 176
pedro Avatar answered Sep 21 '22 21:09

pedro