我正在创建一个包含图像URL的XML文件,在编写XML时必须解析这个URL。
类似于:
images = Image.limit(100) images.each { |i| blah = '' if i.url ??? # process stuff here else blah = '' end }
如果是SQL数据库,我将使用跳过缺少URL的行的查询:
select * from database_table where url is not null
或者类似的东西。数据库查询因数据库而异。
否则,在Ruby中我会做如下事情:
if (i.url.any?) ... else ... end
if (!i.url.empty?)...