Make the most of your tweet
Twitter's 'Tweet Button' has become the standard for websites and blogs around the internet. Yeah, it's that little button to the right of this paragraph.
Run with it (this blog) has had that implemented since day one thanks in large part to the fact that Twitter makes including the button really simple. Just grab the snippet of code and throw it into your html. It took me a little while to realize that the default settings, while great for getting you up and running, do not result in the prettiest of tweets. Here I'll walk you through how to utilize google's url shortener, and get the basic Tweet Button functionality down.
Fundamentals
Twitter allows you to include the button with an iframe or via a snippet of javascript. I'm going to walk through the javascript setup because it's the most convenient and it's also what Twitter recommends. If you go to the Twitter Button resource page you'll be given a set of options to configure your Tweet Button. Once you've figure out how you want it laid out you should have something that looks like this.
Now you'll immediately notice a few things about the above code. First is the use of ssl. Do it [2]. I've snagged the curl PEM [3] which is a reliable authority and stored it in /lib/cacert.pem. Also set the verify_mode to OpenSSL::SSL::VERIFY_PEER. The rest is pretty vanilla net/http stuff.
The next thing you'll notice is the line directly under that, which is where I read in my google api key to keep it out of source control. It makes sense to add an after hook on your cap-deploy script to link to a share location on your production server and then add the file to your ./gitignore. Strictly speaking goo.gl does not require that you submit an api key for url shortening, but it lets you track the urls if you do.
Bringing it back around
Alright so now you have the short url for your site we'll come back to our Tweet Button. Only now we'll set the data-url to our short url. Not so fast! We also have to set the data-counturl to the original url so that your count bubble will be accurate.
# app/views/_tweet_button.html.erb
<a href="https://twitter.com/share" class="twitter-share-button"
data-url="<%= @article.short_url %>"
data-counturl="<%= request.url %>"
data-count="vertical"
data-via="rondale_sc">Tweet</a>
Now we have a decent looking tweet. It's going to use your <title> for your text by default. I think this is a great default as it encourages you to use the <title> properly. I think the easiest way of setting your title tag is to set '<%= yield :head %>' in your layout's <head> tag then:
# in app/view/articles/show
<% content_for :head do %>
<%= content_tag("title", @article.title) %>
<% end %>
And there you have it a nice looking tweet.

Wrap up
Alright, so there you have it a quick and relatively painless way to spruce up your website. There are a number of additional things you can do to further customize your Tweet Button so I encourage you to take a look at the api page which is linked below. If you have you have any questions or ideas let me know in the comments below, or tweet me. Thanks for reading.
References
1.) Tweet Button Docs
2.) Use HTTPS, 2010
3.) Curl PEM
Additional References
Net HTTP cheat sheet
Google Shortener Getting Started
