Damn... after all my searching this pops up AFTER I write the plugin. Oh well, mine's slightly different so I'll go ahead and release it anyways. 

1. Looks like his just writes strings with commas, so it doesn't handle escaping quotes or anything like that.
2. Also, looks like you set the header and fields in the model... whereas with mine you can set them on the fly in the controller.
3. I specifically needed to be able to do this:

respond_to do |wants|
  wants.xml { render :xml => @collection.to_xml }
  wants.csv { render :text => @collection.to_csv }
end

so there is a bit of MimeType code in the plugin as well.
4. I noticed his takes a block. I saw some other similar code that did this and I was considering it... but I just didn't see a  real need for it at the time.

Oh well... to each his own I suppose. Thanks for the link Kevin.

On Aug 30, 2006, at 9:51 AM, Kevin Clark wrote:

So, Scott Raymond just solved your problem:

On 8/30/06, Chris Abad <[EMAIL PROTECTED]> wrote:

Yea, I was keeping that in the back of my mind... just forgot to mention it.
This was bothering me so I had to give this a decent shot before I turned in
for the evening. Here's the whole thing:



So here's what we've accomplished between these two threads:
1. Start with an array of AR objects
2. Check to make sure they are all instances of the same AR class, using the
first instance in the array as a model.
3. Order the attributes of each record in the array in the following manner:
  - Default uses @object.class.column_names as a model for the order (which
is the same order as the columns appear in your db table)
  - if you use the :only option, we'll use that array as the model for the
sort order

As an added bonus, we have :except and :only options to explicitly
include/exclude certain columns for your csv. Thanks for the input so far.
Additional feedback welcome.


On Aug 30, 2006, at 12:51 AM, Jordan A. Fowler wrote:
ARGH! I just totally contradicted a previous statement (which we've both
seemed to ignore). Hashes are not meant to be sorted! The order of keys or
values is not guaranteed. That's what arrays are for. So, the simple
solution here is to say:

@users.to_csv(: ['username','password']).sort.each
do |arr|
  key = arr[0]
  value = arr[1]
# ...
end

-Jordan

_______________________________________________
Sdruby mailing list





-- 
Kevin Clark
_______________________________________________
Sdruby mailing list

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to