2014-02-20 24 views
1

我想通過Instagram返回的數據循環,並顯示在網頁上的信息。 我可以從字面上得到每個領域的工作,除了喜歡或評論計數。出於某種原因,它總是返回所有字段的相同數字(2),即使如果我查看返回的JSON,計數也是明顯不同的。其他一切正常工作,因爲它應該。Ruby on Rails Instagram寶石喜歡和評論數不能正常工作

更具體地說,我使用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 %> 

人有任何想法可能什麼呢?

回答

3

這是一個documented bug在Instagram紅寶石的行爲,可能源於保留字count

建議,這個問題可以通過使用嵌套的散列符號來解決,而不是點符號:

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

工作就像一個魅力!非常感謝。 – shinjin

0

做一個puts instagram.likesputs instagram.comments。我敢打賭,喜歡和評論正在返回一個數組或哈希值,並且您需要更深入一層來獲取實際數量。