开发者

Downloading Tweets into Ruby on Rails database

I'm trying to build an app in Ruby on Rails that stores specified tweets in a database.

I think I'm going to use the Twitter gem, but I'm not sure how to go fr开发者_高级运维om displaying tweets to actually storing them.

Any help or resource links are greatly appreciated!

And which database would be best suited for this application?


When iterating results, you can store them in model objects, which in turn map to tables in sql databases (mysql, postgres, oracle), or documents in nosql dbs like mongodb.

Tweaking an example in the twitter gem's README:

# Find and store the 3 most recent marriage proposals to @justinbieber
Twitter::Search.new.containing("marry me").to("justinbieber").result_type("recent").per_page(3).each do |r|
  MyLocalTweetModel.create!(:from_user => r.from_user, :text => #{r.text}")
end

This can be done with any database, really.

The decision over which database to use depends on many other factors, such as where your app will be hosted, what traffic you expect, how you plan to scale it... and taste is definitely one of these factors, and not an unimportant one. I hate Active Record migrations, for instance, though I like its many other niceties. Active Record is the default ORM rails uses for sql databases.

If you're new to all this, just start on a simple sqlite database with Active Record. There's more of a learning-curve to the alternatives.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜