1
如何禁用activeadmin中的json/xml導出分頁?我無法找出任何解決方案。點擊導出到xml或json時,我只獲取當前頁面。Activeadmin:導出xml/json時禁用分頁
如何禁用activeadmin中的json/xml導出分頁?我無法找出任何解決方案。點擊導出到xml或json時,我只獲取當前頁面。Activeadmin:導出xml/json時禁用分頁
一個解決方案(沒有最好的)是禁用德分頁用的before_filter
controller do
before_filter :disable_pagination, :only => [:index]
def disable_pagination
@per_page = YourModel.count
end
end
這使得只用一個所有記錄頁分頁,所以它要導出所有記錄。
這也可以這樣做,
controller do
def index
super do |format|
per_page = (request.format == 'text/html') ? 30 : 10_000 # to skip the pagination
params[:page] = nil unless (request.format == 'text/html') #It will be working even after we export the CSV on the paginated sections.
@users = @users.order("first_name asc, last_name asc").page(params[:page]).per(per_page)
@users ||= end_of_association_chain.paginate if @users.present?
end
end
end