Back to Blog

Get in Touch

Rails Template: Create a Twitter Application in Seconds

By Michael Bleigh April 3, 2009 in rails, twitter, twitterauth, template

Missing

TwitterAuth has been out for a little while and has received some great feedback. Dr. Nic released a great template that lets you quickly build a TwitterAuth app for deployment to SliceHost and since I have some plans for a number of Twitter applications I wanted to try my own hand at writing one up.

If you have Rails 2.3, all you need to do is run this:

rails -m http://github.com/mbleigh/rails-templates/raw/master/twitterapp.rb yourappname

Changing yourappname to the directory in which you want to generate your application. The template will then prompt you for three things:

  • What is your application called? Just give it a title for the pretty template generators.
  • OAuth Consumer Key: The consumer key that you register at http://twitter.com/oauth_clients
  • OAuth Consumer Secret

It will also ask you if you want to install missing gems and go ahead and generate your databases and run migrations. Once you’ve responded through the prompts though, you’re good to go! Just switch to your application’s directory and script/server. Your http://localhost:3000 should look like this:

When you click on Login via Twitter you will be taken to the Twitter OAuth approval page.

Twitter will then send you back to your application, and guess what? You’re logged in!

You can now build on top of this without having to worry about the basic authentication stack. If you aren’t familiar with TwitterAuth, it works a lot like RESTful Authentication, so it should be easy to pick up.

Enjoy, and I hope you find it useful!

Medium

Michael Bleigh

Michael has been with Intridea since 2007 and works to build Intridea's portfolio of products. With many years of experience working as both a designer and a developer, Michael specializes in helping to bridge the gap between the back-end development and the front-end design of a project. Michael is a prolific member of the Ruby on Rails community, having released popular open source libraries such as OmniAuth and spoken at conferences including RailsConf and RubyConf.

More posts by Michael Bleigh

Michael Bleigh

To the troubling idea isn't about what signal you're sending to your employee...

Michael Bleigh

Node.js has a pattern that I personally enjoy: if you require a directory, it...

Michael Bleigh

Last weekend I had the opportunity to speak at RubyConf 2012 about a topic th...