Trying to local variable passed to a partial in a find call and getting nowhere

My code is…
controller
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)

view - monthly.html.erb
<%= render :partial=>“monthly_report”, :collection => @ziplist %>

view - _monthly_report.html.erb
<%= @oxtotalstring = Household.find(:all, :conditions =>
[“households.zip = ?,households.id=visits.household_id,
visits.month=?, visits.year = ?, visits.monthly = ‘1’”,
monthly_report, datestart.month, datestart.year ], :include
=> :visits, :order => “zip” ) %>

model
class Visit < ActiveRecord::Base
belongs_to :household
class Household < ActiveRecord::Base
has_many :visits, :dependent => :destroy

when I try this, the monthly_report variable in the partial looks like
this…
Household_zip: “01537”

The only reason I’m using a find call here is that later in the code I
need to render a partial for each record found, then see child tables
from that variable, as in monthly_report.people. From what I’ve seen,
this functionality is lost using find_by_sql.

if I remove the ? and monthly report from the find call and put a
sample zip code in, it works fine. Is there some way to translate this
to a string I’m missing? I tried monthly_report.to_s and got the same
result.

Thanks for the help

Bob S. [email protected]

first of all, that huge chunk of code in you controller should go in
your
model, controllers are suppose to remain thin and models are suppose to
be
fat,
second use named scopes that query you have could be very small and
readable
with named scopes, and use helpers you have a mess of code in you view
and
those are the main problems.

Use monthly_report[“Household_zip”]