I'm retrieving some API information in the following fashion
fetch_api.each do |api|
save_api = Record.new(name: api.name, height: api.height)
save_api.save!
end
Most records get saved, no problem. But it seems some are missing height and some name. This causes NoMethodError with undefined method "height" or "name" for nil:NilClass, breaking the loop.
I don't mind if a single record doesn't have its value. How can I continue the loop after this?
I tried
if !save_api.save
next
end
with no effect. (Edit: Also tried to save without "!"). Each block doesn't seem to accept rescue
. What else is there?
Thanks so much in advance