在rails c中使用它时工作
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: "wiz123tjh@gmail.com", handphone: "1234006", since: nil, created_at: "2010-12-14 18:28:01", updated_at: "2010-12-14 18:28:01">]
答案 0 :(得分:2)
字符串插值仅适用于双引号,而不适用于单引号。改变行
tweets = client.query('#barcampmlk2 #{sess.hash_tag} +1')
到
tweets = client.query("#barcampmlk2 #{sess.hash_tag} +1")