Created
March 7, 2011 12:35
-
-
Save philhawksworth/858447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base62' | |
... | |
# mint a URI for a lolly | |
post '/mint' do | |
message = params[:message].gsub(/'/,"''") | |
db.execute( "insert into lollies (message, image) values ('"+ message +"','#{params[:lolly]}')" ) | |
if request.xhr? | |
id = db.execute( "SELECT last_insert_rowid() FROM lollies" )[0].to_s() | |
id = id.to_i.base62_encode | |
#prepare a clip and link to tweet. | |
link = ' http://vlolly.com/'+id | |
if message.length + link.length > 140 | |
link = '...' + link | |
end | |
clip = escape(message[0, 140 - link.length] + link) | |
'<div>Here\'s your link, send it to someone who deserves some sugar <a href="/'+id+'">http://vlolly.com/'+id+'</a></div><div> Or perhaps you might like to <a href="http://twitter.com/home?status='+clip+'">tweet it.</a></div>' | |
else | |
erb :yours | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment