如何在有效管理员中对自定义页面进行分页? 我在活动管理员中创建了一个自定义索引页面,并希望实现分页。请建议我实施分页的方法。
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
答案 0 :(得分:0)
我们遇到了类似的问题,我们使用paginated_collection
方法解决了这个问题,
下面的内容可能有效(此代码未经过测试!),
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
希望这有帮助!