2010-12-14 107 views
0

在軌使用此當c問題與Twitter的搜索API

client = TwitterSearch::Client.new('campvote') 

tweets = client.query('#barcampmlk2 #railsforzombies +1') 

,但不是在BarcampSession.update_twitter!它重新調整空哈希

require 'twitter_search' 
class BarcampSession < ActiveRecord::Base 
    validates :hash_tag , :format => {:with => /^#\w+/ } , :presence => true ,:uniqueness => true 
    validates :name , :presence => true 
    validates :email , :presence => true , :format => {:with => /((\S+)@(\S{3}[a-zA-z0-9)]\S*))/ } 
    validates :handphone, :presence => true 

    def self.update_twitter! 
     client = TwitterSearch::Client.new('campvote') 
     BarcampSession.all.each do |sess| 
      tweets = client.query('#barcampmlk2 #{sess.hash_tag} +1') 
      puts tweets.to_yaml 
     end 

    end 
end 

工作交回

rb(main):014:0> BarcampSession.update_twitter! 
--- !seq:TwitterSearch::Tweets [] 

=> [#<BarcampSession id: 1, hash_tag: "#railsforzombies", name: "wizztjh", email: "[email protected]", handphone: "1234006", since: nil, created_at: "2010-12-14 18:28:01", updated_at: "2010-12-14 18:28:01">] 

回答

2

路線插值只能用雙引號,而不是單引號。行

tweets = client.query('#barcampmlk2 #{sess.hash_tag} +1') 

更改爲

tweets = client.query("#barcampmlk2 #{sess.hash_tag} +1")