class CouponController < ApplicationController
def index
@coupons = Coupon.all.page(params[:page])
@coupons = @coupons.for_amount(params[:amount]) if params[:amount].present?
@coupons = PaginatingDecorator.new(@coupons)
respond_with(@coupons) do |format|
format.html
format.csv { render :text => coupons_csv }
end
end
private
def coupons_csv
column_names = %w(code name id amount expiration_date)
CSV.generate do |csv|
csv << column_names
@coupons.each do |coupon|
csv << column_names.map{ |attr| coupon.public_send(attr) }
end
end
end
Here in coupons_csv I'll not receive the entire coupon list - I'll receive only the paginated set.So what would be the best way to get ALL filtered coupons into the csv and get per-page#paginated coupons in the index page?
What if we have something like
Here in coupons_csv I'll not receive the entire coupon list - I'll receive only the paginated set.So what would be the best way to get ALL filtered coupons into the csv and get per-page#paginated coupons in the index page?