class UrlController < ApplicationController
def create_url
if request.post? and params[:redirect_to]
@url = Url.new(:redirect_to => params[:redirect_to]
render :text => @url.link_for(thing) if @url.save
end
end
private
def thing
"#{request.protocol}#{request.host}#{request.port_string}"
end
end
class Url < ActiveRecord::Base
def before_create
self.redirect_to = redirect_to.gsub!(/^http:\/\//, "")
# plus n??
self.url = String.random(Url.count.size)
end
def link_for(thing)
"#{thing}/#{url}"
end
end