ruby on rails - Setting Multiple Variables to Result of Query -
i have query below, return city , state shortest distance between inputted set of points , rows of table metros
:
@lat = row[latitude] @long = row[longitude] metros.select( "major_city , major_state ,(latitude - " + @lat + ")**2 + (longitude - " + @long + ")**2 'distance'") .group("major_city,major_state").limit(1).order('distance asc')
what need set result 2 variables row[major_city]
, row[major_state]
major_city
set row[major_city]
, major_state
row[major_state]
.
how can accomplish task 2 allow setting 2 variables independently?
it comes out activerecord::relation type if 1 piece of result, use .first , take single record may work.
Comments
Post a Comment