Trying to do a report with a list of zip codes and getting stuck..

I'm trying to get a list of zip codes in my database with

zipstring = sprintf("select distinct zip from visits,households where " +   "households.id=visits.household_id and visits.month='%2d' and visits.year = '%4d' " + "and visits.monthly = 1 order by households.zip;", datestart.month, datestart.year, dateend, datestart)

@ziplist = Household.find_by_sql(zipstring)

this gives me an array of zip codes. Then I use

  <%= render :partial=>"monthly_report", :collection => @ziplist %>

to run monthly_report for each zip code. This is where the problem is. If I try to put the variable into a find call, it isn't text.

If I look at it in the debugger, it's

#<Household zip: "01501">

and .to_s is

"#<Household:0xb68ad9e4>"

All I need is the 01501 part, but I'm getting the memory address in my find call. Please help.

Thanks

Bob Smith <bsm2th@gmail.com>

By the way, those variables are monthly_report from the render :partial call.

Bob

Can you not just use .zip on each element to get what you want?

Colin

He could. Or since he's bypassing AR (for the most part) it might be easier to do...

@ziplist = Household.connection.select_values(zipstring)

From the docs.... select_values(sql, name = nil) Returns an array of the values of the first column in a select: select_values("SELECT id FROM companies LIMIT 3") => [1,2,3]

-philip

I ended up with the .zip method. Didn't realize that the response from the select was a collection, even with only one field.

Thanks Bob