Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tweet this link in rails app

I am surprised I couldn't find it on google, what's the best way to add a "tweet" this link to post a url and a description to the user's twitter account?

like image 302
badnaam Avatar asked Aug 03 '10 07:08

badnaam


1 Answers

The 'tweet this link' feature is extremly simple and does not require additional Rails features. It is as simple as:

<a href=http://twitter.com/home?status=Name_and_Address_of_the_twitter_post_that_you_want_everyone to_see_on_twitter>Add to Twitter</a>

To use Rails code, it would be something like:

= link_to "tweet me", "http://twitter.com/home?status=#{@post.short_name} #{post_url(@post)}"

Some remarks:

  • the status should not be bigger than 140 chars (you can use either an external service as bit.ly or you can write your own controller that answers to small addresses and that redirects to the post)

  • you can also implement a tracking mechanism that could detect how many users clicked on the 'tweet this' link

like image 58
Vlad Zloteanu Avatar answered Sep 28 '22 06:09

Vlad Zloteanu