这是我所拥有的:
def existing_photos
@existing_photos = Array.new
event.photos.each do |ep|
@existing_photos << URI.unescape(ep.dropbox_path.split('/').last) rescue []
end
@existing_photos
end
它从数据库查询中返回一个文件名数组。我敢肯定有一种更像红宝石的方式来做到这一点。
我也有一个类似的方法,它对 dropbox-apils
结果做同样的事情。
def all_photos
@all_photos = Array.new
@dropbox_files.each do |dbf|
@all_photos << dbf.path.split('/').last
end
@all_photos
end
我认为也应该优化。提前致谢!