On Sep 10, 11:52 am, Philip Hallstrom <phi...@pjkh.com> wrote:
> > On 10 September 2010 05:41, Bob Smith <bsm...@gmail.com> wrote:
> >> 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.
>
> > Can you not just use .zip on each element to get what you want?
>
> 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

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to