Hi all,
I have a books controller in which i have a list of all books displayed.
I want to have a csv download option.
The point is that i want csv download according to the pagination.
When i click on first page and click csv download i need to get only first 2 records(per page=>2)
When i click on the second page i want the csv file with next 2 records.
Please guide me where i went wrong.
Here is my controller:
def index
@books = Book.paginate(:all, :page=>params[:page], :per_page=>2)
datestamp = Date.today.strftime("%d%b%Y%H")
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @books }
format.csv do
csv_data=FasterCSV.generate do |csv|
csv << ["Serial", "Name","Description", "pages","isbn", "Created At", "Modified At"]
@books.each do |b|
csv << [[b.id](http://b.id),[b.name](http://b.name),b.description,b.pages,b.isbn,b.created_at,b.updated_at]
end
end
end
send_data csv_data,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=books"+datestamp+".csv"
flash[:notice] = "Export complete!"
end
end
end
Thanks in advance.