我正在使用Instagram api在Rails中构建一个站点。我似乎想不出如何用任何图像来提取标题文本,而且它似乎也没有说明如何在文档中的任何地方这样做。是否可以使用api,还是必须使用其他东西?
我附加了两个非常简单的代码片段来说明我的问题
红宝石:
class HomeController < ApplicationController
def index
def index
@instagram = Instagram.tag_recent_media("blablabla", {:count => 50})
end
end
end下面是HTML:
<div class = "tagged-images-container-position">
<% @instagram.each do |instagram| %>
<%= instagram.caption.text %> <!-- THIS LINE DOESN'T WORK -->
<%= instagram.user.username %>
<%= image_tag(instagram.images.standard_resolution.url, class: "tagged-images") %>
<% end %>
</div>发布于 2014-02-14 16:31:13
尝试检查标题文本是否为null,然后再进行文本说明。我发现有时它会弹出为null。
发布于 2014-02-19 01:43:23
具体来说,在深入到caption.text之前,检查整个标题,看看它是否为零。
这种技术一直适用于我:
if instagram.caption
caption = instagram.caption.text
else
caption = "Oops, no caption."
endhttps://stackoverflow.com/questions/21445805
复制相似问题