Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created February 15, 2009 01:45
Embed
What would you like to do?
a commonly needed server side component: expand tinyurl (et al)
class BigurlsController < ApplicationController
def index
url = URI.parse(params[:url])
res = Net::HTTP.start(url.host, url.port) {|http| http.get([url.path, url.query].compact.join('?'), "User-Agent" => request.user_agent) }
render :text => (res['location'] || params[:url])
rescue
"#{params[:url]}##{$!.to_s}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment