# Help With Search Function in Model

**URL:** <https://www.ruby-forum.com/t/help-with-search-function-in-model/131089>\
**Category:** Rails\
**Created:** [March 5, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/help-with-search-function-in-model/131089 "2008-03-05T22:33:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 5, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/help-with-search-function-in-model/131089/1 "2008-03-05T22:33:17Z")

</div>

Hello Everyone,

I am pretty new to ROR and am stuck on how to proceed. I have an  
application that stores businesses along with there delivery boundaries.  
The boundaries are stored as 4 latitude/longitude points. When a user  
does a search they enter there address and I need to bring back all of  
the businesses that deliver to them.

I use whatâ€™s called a Point in Poly algorithm to determine if a business  
delivers to the input address.

In my controller I set the result variable to a call to Search in the  
model like soâ€¦

@businesses = Business.search(params[:search])

In my model I haveâ€¦

def self.search(search)  
@all Businesses= find(:all)

for bus in 0…@ @all Businesses.length  
if( inPoly?(How do I get the attributes of bus to pass to inPoly?))  
How Do I add this bus to my result list?  
end  
end

How do I return my new list to the controller?  
end

def self.inPoly?(point1,point2,point3,point4,testPoint)  
I can do this  
end

What I am really stuck on is how I can build my list in my search  
function. I am not sure how to access the attributes of each business in  
the for loop. And I am not sure how to return the result to the  
controller. Any help at all would be really apprectiated.
