On Apr 1, 2009, at 10:39 PM, Xavier Lange wrote:
>
> I am trying to generate CSVs from large datasets while trying to avoid
> the mutex. When I use render_deferred to free up the server process I
> find that I cannot use send_data as I'd like. The data is returned to
> render, just as advertised, so anything having to do with displaying
> the data as an attachment is gone. I can tell the users to Right Click
> and Save As..., but I thought I'd ask if there was a better way. Any
> ideas on how I can use send_data and not lock up the server?
Can you find a way for your csv to be rendered row by row? If you can
make an object that responds to #each and yields lines of csv then you
can just return that from your action and you should be good to go:
class CSVWrapper
# set up your csv here somehow so that it can be iterated.
def initialize(something)
@csv = something
end
# iterate your CSV and yield lines for rack to output
def each(&blk)
@csv.each_line do |line|
blk.call(line)
end
end
end
# controller
class Foo < Application
def csv
return CSVWrapper.new(whatever)
end
end
Something like that should get you where you want.
Cheers-
Ezra Zygmuntowicz
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---