Question

How to paginate a custom page in active admin? I created a custom index page in active admin and want to implement pagination. Please suggest me a way to implement pagination.

ActiveAdmin.register "Requested Videos" do
  menu priority: 4  
    breadcrumb do
      [
        link_to('Dashboard', '/admin')
      ]
    end
        content do
            div :class => 'panel' do
             # h3 t("Requested Videos")
              div :class => 'panel_contents' do
                div :class => 'attributes_table category' do

                    table do
                        tr do
                          th { "Name" }
                          th { "Uploader Name" }
                          th { "Uploader Email" }
                          th { "Link" }
                          th { "Description" }
                          th { "Actions" }
                        end 
                    Video.where(visibility: false).page(params[:page]).per(10).each do |video|      
                        tr do 
                            td { video.name }
                            td { video.uploader_name }
                            td { video.uploader_email }
                            td { link_to video.link, video.link, target: '_blank' }
                            td { truncate(video.description, omision: "...", length: 100) }
                            td { button_to("Accept", accept_path(video)) }
                            td { button_to("Reject", decline_path(video), method: :delete, :data => { :confirm => 'Are you sure, you want to reject the video?' })}

                        end
                      end # table
                    end  
                end # attributes_table
              end # panel_contents          
        end     
    end     

end
Était-ce utile?

La solution

We ran into a similar problem, we solved it by using the paginated_collection method,

Something like below might work (this code is not tested!),

paginated_collection Video.where(visibility: false).page(params[:page]).per(10) do
  collection.each do |video|
    tr do 
      td { video.name }
      td { video.uploader_name }
      td { video.uploader_email }
      td { link_to video.link, video.link, target: '_blank' }
      td { truncate(video.description, omision: "...", length: 100) }
      td { button_to("Accept", accept_path(video)) }
      td { button_to("Reject", decline_path(video), method: :delete, :data => { :confirm => 'Are you sure, you want to reject the video?' })}
    end
  end
end

Hope this helps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top