【问题标题】:Ruby on Rails Instagram Gem like and comment count not working properlyRuby on Rails Instagram Gem 喜欢和评论计数无法正常工作
【发布时间】:2014-02-20 01:54:11
【问题描述】:

我正在尝试遍历 Instagram 返回的数据并在网页上显示信息。 除了喜欢或评论计数之外,我几乎可以让每个领域都工作。出于某种原因,它总是为所有字段返回相同的数字 (2),即使我查看返回的 JSON,计数也明显不同。其他一切都正常工作。

更具体地说,我正在使用 Ruby on Rails Instagram Gem,使用 tag_recent_media(user) 方法获取数据。

  def index
        result = []
        next_id = nil
        while result.length < 100
            data = Instagram.tag_recent_media(4, max_id: next_id)
            next_id = data.pagination.next_max_id
            result.concat(data)
        end

        @results = result.paginate(:page => params[:page], :per_page => 30)
  end  

在我的 html.erb 中:

<% @results.each do |instagram| %>
instagram.images.standard_resolution.url //gives me image url correctly
instagram.caption.text //gives me caption text correctly
instagram.user.username //gives me the username correctly
instagram.likes.count //always gives me 2!
instagram.comments.count //always gives me 2!
<%end %>

有人知道会发生什么吗?

【问题讨论】:

    标签: ruby-on-rails ruby json ruby-on-rails-3 instagram


    【解决方案1】:

    这是 Instagram Ruby Gem 行为中的 documented bug可能源于单词 count 被保留。

    建议可以通过使用嵌套哈希表示法而不是点表示法来解决该问题:

    instagram.likes[:count]
    instagram.comments[:count]
    

    【讨论】:

      【解决方案2】:

      执行puts instagram.likesputs instagram.comments。我敢打赌,likes 和 cmets 会返回一个数组或哈希值,您需要更深入一层才能获得实际计数。

      【讨论】:

        猜你喜欢
        • 2013-07-15
        • 1970-01-01
        • 1970-01-01
        • 2013-05-26
        • 1970-01-01
        • 1970-01-01
        • 2021-04-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多