I have a strange problem with the FastImage gem. When I try to access the variable directly or call methods on it, I get a nil error. Rails says that the variable doesn’t exist, so something like FastImage.size(url)[0] won’t work. However, if I use ‘puts’, i.e puts FastImage.size(url) the variable can be accessed.
In the console, everything is working fine. Any ideas?
images.each do |d|
puts FastImage.size(d["src"])[0] + FastImage.size(d["src"])[1]
results << d["src"]
end
Figured it out! What happens is that FastImage throws an error if there is a bad url, so one needs to check that the url is valid. What happened was that one of the urls was invalid, so it would throw an exception midway through the iteration.