Shawn Lindsey

Twitter integration into a rails 3.x application

Adding your twitter feed, or the twitter feed of anyone else for that matter can be done with less than 10 lines of code by including the "twitter" gem in your Rails application. This code will return the most recent tweet to the view.

Start with adding the following to your Gemfile

gem twitter

Now from the command line do a

bundle install

Restart your server.

in appliation.rb (other places can work too) add this code.

require "twitter"

In the controller add the following code to your specific view method. Do not include the "@", just the username

@twitter_feed = Twitter.user_timeline("Twitter-User-Name").first.text

In the view now, just add the following code.

<%= @twitter_feed %>

That is it! Your latest tweets will show up in your rails application. For more information and documentation please go to http://twitter.rubyforge.org/

 

Shawn Lindsey

Categories

Other Posts

RSS Feed

Subscribe

Archives