I am new to Ruby (and Rails) and was hoping you could help resolve some of the confusion I encountered.
I am trying to integrate Twitter on my website to get the latest user twist and capture a link to their profile picture. The gem works fine until, as it seems to me, the 100th API call in an hour, after which Twitter will disconnect you.
From what I compiled, I need to cache the result for ~ 1 minute using memcache. There was a big pseudocode here , but unfortunately it was a little over my head. I was hoping I could get some more details.
At the moment, I'm not sure where I can place this code? I want to display twitter information in the layout view of the application, so that it goes to the method in the application_helper.rb file?
My best attempt to find out was to lead to the following code that throws an "Missing Helper File" error.
module ApplicationHelper require "memcache" def twitter cache = MemCache.new twitter = cache.get("twitter").first if twitter.nil? begin twitter = Twitter.user("TwitterName") cache.set("twitter", twitter, :expires_in => 1.minute) if twitter rescue twitter = default end end return twitter end end
source share