I'm trying to export a list of Ransack (Railscast) results to a CSV file (Railcast). However, it keeps exporting all of the objects, instead of the results returned by the Ransack search. Can anyone tell me where I'm going wrong?
In the Reports controller, I've tried passing both @bookings and @search.result:
def index
@search = current_user.bookings.search(params[:q])
@bookings = @search.result
@search.build_condition
respond_to do |format|
format.html
format.csv { render text: Booking.to_csv(@bookings) }\
end
end
And then the Booking to_csv method:
def self.to_csv list
CSV.generate do |csv|
csv << column_names
list.each do |booking|
csv << booking.attributes.values_at(*column_names)
end
end
end
Yet every time, I get the unfiltered list of current_user.bookings. Why?
@bookings
contain what you want? – Jabotlist
method argument in parens, but that's not a syntax issue. Have you tried logginglist
and eachbooking
from within yourto_csv
method? – Jabot