Ah, read the name wrong. Either way.. does that do it?
On 8/30/06, Kevin Clark <[EMAIL PROTECTED]> wrote:
So, Scott Raymond just solved your problem: http://rubygreenblue.com/blog/article/convert_model_data_to_csv 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: > > > http://pastie.caboo.se/10865 > > 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(:only => ['username','password']).sort.each > do |arr| > key = arr[0] > value = arr[1] > # ... > end > > -Jordan > > _______________________________________________ > Sdruby mailing list > [email protected] > http://lists.sdruby.com/mailman/listinfo/sdruby > > > -- Kevin Clark http://glu.ttono.us
-- Kevin Clark http://glu.ttono.us _______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
