Nevermind, figured it out. I am stupid.
changed
r.zipcode = result[0]["zip"]
to
Source.update(r.id, {:zipcode => result[0]["zip"]})
Justin Copeland wrote:> This is a stupid question I know, but it is driving me crazy - I am
> missing something simple and basic here. I am trying to update missing
> zip codes on a data table. I am doing something incorrectly as the data
> in the Source table is not being updated, only the value in the array is
> changed. How do I get this to update the actual DB record instead?
>
> def add_missing_zips
> #find all records in source table that don''t have zip codes
> no_zips = Source.find(:all, :conditions => [ "zipcode = ?",
(nil ||
> '''') ])
> @starting_no_zips = no_zips.length
> server =
XMLRPC::Client.new2("http://geocoder.us/service/xmlrpc")
> no_zips.each do |r|
> result = server.call("geocode", r.full_address)
> #update the record in the Source table if a zip code is found
> unless (result.empty? || result[0]["zip"] ==
('''' || nil))
> r.zipcode = result[0]["zip"]
> end
> end
> end_no_zips = Source.find(:all, :conditions => ["zipcode =
?", (nil
> || '''') ])
> @ending_no_zips = end_no_zips.length
> end
--
Posted via http://www.ruby-forum.com/.