brighterplanet/earth — comment on commit 3a9fade25c590f3602690e464fa4374824f410d3
File: lib/earth/locality/country/data_miner.rb line 107
By seamusabshere:

check out the docs for update_all on http://api.rubyonrails.org/

if you're doing literal (simple) assignments in the "updates" or literal comparisons in the "conditions," use ruby hashes so that you don't have to worry about escaping

update_all({ :aircraft_description => aircraft.description.downcase }, :aircraft_bts_code => bts_code) # note parentheses that are required to distinguish between the two arguments, both of which are hashes

if you're doing complex assignments or comparisons, write the sql manually.

update_all "type_year_name = type_name || ' ' || year" # note pipes are concat AND single quotes required for strings (in this case a single space)
update_all 'seats_per_flight = 1.0 * seats / flights', 'flights > 0' # note explicit float

it's possible but not usually necessary or even preferable to use Arel

update_all("fuel_efficiency = (#{relation.to_sql}), fuel_efficiency_units = 'kilometres_per_litre'", "fuel_efficiency IS NULL") # note that you're still writing sql manually... and here too there are single quotes around the units