twitter user tweets

May 13, 2009 at 6:02 pm (Twitter) (, , )

The following code describes the way we can fetch the tweets of the user.

I just came across this wonderful GEM to integrate TWITTER in rails.
This is called Twitter4r

Its API is available at API

Its such an easy gem to use. I thought i shall throw the steps needed for the most regular task needed….Getting the tweets of a particular user.

Install twitter4r.

require “twitter”

twitter = Twitter::Client.new(:login=>”login_name”,:password=>”password”)tweets = twitter.timeline_for(:user,:id=>”user_name_of_user_whose_tweets_you_need”)
The result is an array
The important attributes of this array-elements are:
@text – The text of this tweet
@user – The user who posted this tweet
@user.name – name of the user who posted this tweet.
@user.screen_name – screen name of the user who posted this tweet

Hope this is useful.

Permalink Leave a Comment

passing optional parameters to partials

May 13, 2009 at 4:38 pm (Partials) (, , , )

Today i got an instance where i want to use a parameter in the partial, which may or may not be passed.This partial is called from two places, one which passes while other does not pass a specific parameter. The partial just displays the parameter value.

<%= passed_parameter %>

If an instance variable is used, the <%= … %> will result in an empty string if the instance variable (@abcdef) id not defined. But if its a local variable like the one passed to the partials using LOCALS, it will throw an error.

In these cases, the best thing to do is, add this at the first line of the PARTIAL.

<% passed_parameter ||= DEFAULT_VALUE %>

This has to be done for whatever optional parameters might be used.

Permalink Leave a Comment