ruby on rails - Live Twitter Stream -
i'm programming application in ruby on rails v(2.0.0/4.0.0) , trying integrate live twitter feed specific source (@u101) onto basic html page , don't understand how. after googling around few hours i've seen few different gems seem integrate twitter (tweetstream, twitter api, twitter), however, can't of these work. i've followed guides such http://www.phyowaiwin.com/how-to-download-and-display-twitter-feeds-for-new-year-resolution-using-ruby-on-rails , 1 in particular gives me error:
irb(main):002:0> tweet.get_latest_new_year_resolution_tweets nameerror: uninitialized constant twitter::search c:/sites/easybakeoven/blog/app/models/tweet.rb:6:in `get_latest_new _year_resolution_tweets'
which don't understand. if walk me through necessary steps accomplish goal or point me in right direction i'd thankful.
update: model: tweet.rb
class tweet < activerecord::base #a method grab latest tweets twitter def self.get_latest_new_year_resolution_tweets #create twitter search object search = twitter::rest::client.new #grab recent 100 tweets contain 'new year resolution' words, , loop each of them search.containing("u101").result_type("recent").per_page(100).fetch.each |tweet_results| #parsing string 'created_at' datetime object twitter_created_at = datetime.parse(tweet_results.created_at) #making sure not saving exact same tweet person again unless tweet.exists?(['twitter_created_at = ? , from_user_id_str = ?', datetime.parse(tweet_results.created_at), tweet_results.from_user_id_str]) #finally creating tweet record tweet.create!({ :from_user => tweet_results.from_user, :from_user_id_str => tweet_results.from_user_id_str, :profile_image_url => tweet_results.profile_image_url, :text => tweet_results.text, :twitter_created_at => twitter_created_at }) end end end end
tweets_controller.rb
class tweetscontroller < applicationcontroller def index #get tweets (records) model ordered 'twitter_created_at' descending @tweets = tweet.order("twitter_created_at desc") end end
index.html.rrb:
<h1>tweets#index</h1> <div id="container"> <ul> <% @tweets.each |tweet| %> <li class="<%=cycle('odd', '')%>"> <%= link_to tweet.from_user, "http://twitter.com/#{tweet.from_user}", :class => "username", :target => "_blank" %> <div class="tweet_text_area"> <div class="tweet_text"> <%= tweet.text %> </div> <div class="tweet_created_at"> <%= time_ago_in_words tweet.twitter_created_at %> ago </div> </div> </li> <% end %> </ul> </div>
also again i'm trying display tweets '#u101'
in particular tutorial used, go line 7 in app/models/tweet.rb , you'll see:
search = twitter::search.new
replace with
search = twitter::rest::client.new
this recent change ruby gem. can see what's current in documentation!
Comments
Post a Comment