Searching table question

this confuses me…

@zip = ZipCode.find(zip)

where @zip is the first 3 digits of a zipcode
the table is zipcodes the model zipcode

so i understand @zip = Zipcode.find(zip) is attempting to look for zip
in the zipcodes table via the model zipcode

however i need to compare my 3 digit zip (@zip) againt two columns in
the table
column 1 - zipstart
column 2 - endzip

i need to find the row that my @zip falls inside the values of those
two columns, so i believe this line of code is too simple

example might be @zip = 034
startzip = 032 and endzip =037 in the table
i need to identify that row

can anyone help?

On Nov 5, 2007, at 9:09 PM, agilehack wrote:

i need to find the row that my @zip falls inside the values of those
two columns, so i believe this line of code is too simple

example might be @zip = 034
startzip = 032 and endzip =037 in the table
i need to identify that row

(inside class ZipCode)

def self.find_between(zip)
find(:first, :conditions => [‘startzip <= ? AND endzip >= ?’,
zip, zip])
end

and in your controller

@zip = ZipCode.find_between(zip)