0

I have a user's list, when click on 'show activities' this shows a list of user activities in a modal from partial file _user_activities.html.haml. This activities list is a paginated view. I want to add pagination only for this activities alone inside my modal window. How to do this? I am already using will_paginate, that makes my page to reload. How to achieve this?

users/index.html.haml

%table
  %thead
    %th Name
    %th Actions
  %tbody
    - @users.each do |user|
      %tr
        %td= user.name
        %td
          %i.icon-play
          %div.modal.hide
            = render 'user_activities', user: user

= will_paginate users

:javascript
  $('i').click(function() {
    $(this).next(.modal).modal('show');
  });

users/_user_activities.html.haml

%table
  %thead
    %th Name
    %td Type
  %tbody
    - user.activities.eadch do |activity|
      %tr
        %td= activity.name
        %td= activity.type

= will_paginate user.activities
madth3
  • 7,275
  • 12
  • 50
  • 74
Achaius
  • 5,904
  • 21
  • 65
  • 122

2 Answers2

2

One way to achieve the ajax type pagination is with Kaminary gem. We can easily set up the pagination with Kaminary. I don't know how to achieve the ajax type pagination with will_paginate, but i used kaminary in my one of project and its quite easy with this.

update

Check How to Implement ajax pagination with will_paginate gem for providing the ajax type pagination with will_paginate.

Community
  • 1
  • 1
Sagar Bommidi
  • 1,409
  • 8
  • 12
0

You can use kamiray or will_paginate gem very easy to use have a look at following example using will paginate,

do this in your controller and it will add pagination.

@set = SomeObject.paginate(:page       => params[:page],
                           :per_page   => 20,
                           :order      => 'created_at DESC',
                           :conditions => { :foo => 'bar' })

here is a railscast for Kaminary and willpaginate Hope it would solve your problem.

Muhamamd Awais
  • 2,385
  • 14
  • 25
  • I want to do this in table inside a modal window, not in ordinary page. I achieved pagination in my normal page using will_paginate – Achaius Mar 26 '13 at 08:05
  • i believe if you have achieved pagination for normal page then it would be same when you would be using bootstrap. Otherwise you have to show your code. – Muhamamd Awais Mar 26 '13 at 08:13