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

**URL:** <https://www.ruby-forum.com/t/trying-to-local-variable-passed-to-a-partial-in-a-find-call-and-getting-nowhere/194674>\
**Category:** Rails\
**Created:** [September 8, 2010, 9:09pm UTC](https://www.ruby-forum.com/t/trying-to-local-variable-passed-to-a-partial-in-a-find-call-and-getting-nowhere/194674 "2010-09-08T21:09:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [September 8, 2010, 9:09pm UTC](https://www.ruby-forum.com/t/trying-to-local-variable-passed-to-a-partial-in-a-find-call-and-getting-nowhere/194674/1 "2010-09-08T21:09:41Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [September 8, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/trying-to-local-variable-passed-to-a-partial-in-a-find-call-and-getting-nowhere/194674/2 "2010-09-08T22:36:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [September 9, 2010, 9:02am UTC](https://www.ruby-forum.com/t/trying-to-local-variable-passed-to-a-partial-in-a-find-call-and-getting-nowhere/194674/3 "2010-09-09T09:02:59Z")

</div>

Use monthly\_report[“Household\_zip”]
