开发者

How do I convert a Twitter API Pull into an Array in Ruby On Rails?

开发者 https://www.devze.com 2023-01-04 12:05 出处:网络
I am trying to create a stream that includes Twitter data + my app\'s but I\'m having trouble with this because Twitter\'s data isn\'t properly coming out as an array. This is my code:

I am trying to create a stream that includes Twitter data + my app's but I'm having trouble with this because Twitter's data isn't properly coming out as an array. This is my code:

answers = Answer.find(:all, :conditions => {:user_id => @user_id }, 开发者_高级运维:limit => 20)
tweets = Twitter::Search.new(params[:username])

@feed = (answers + tweets).order_by(&:created_at)

Any suggestions would be greatly appreciated.


It looks like you're using the Twitter Gem? In which case, the Search class is Enumerable and you can therefore call to_a on an instance of it. So...

tweets = Twitter::Search.new(params[:username]).to_a
@feed = (answers + tweets).order_by(&:created_at)
0

精彩评论

暂无评论...
验证码 换一张
取 消