Ruby on Rails Monday, May 2, 2011

The send_data function is useful when you have a bunch of data on the server that needs to be streamed to the client.

Since your data is stored in a JavaScript variable (already on the client), using send_data means that this data will need to be posted back to the server, then sent back to the client using send_data. Not very efficient.

Perhaps you can use some JavaScript function to convert your data then present it to the user as CSV. Should be relatively quick since the data is already on the client.

I found this function which will create CSV from JSON:
http://www.zachhunter.com/2010/11/download-json-to-csv-using-javascript/

It may not fit your needs exactly, but the relevant line is the following:

window.open( "data:text/csv;charset=utf-8," + escape(str))

As long as the str variable contains comma-separated data, this should work fine.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment