Skip to content

Instantly share code, notes, and snippets.

@geronimod
Created November 3, 2012 03:27
Show Gist options
  • Save geronimod/4005700 to your computer and use it in GitHub Desktop.
Save geronimod/4005700 to your computer and use it in GitHub Desktop.
Route handler
ActionController::Routing::Routes.draw do |map|
...
map.connect ':route', :controller => 'route_handler', :action => 'rewrite'
...
end
class RouteHandlerController < ApplicationController
def rewrite
# suponiendo una estructura RewriteRule(short_uri, uri, ...) ie:
# "things-to-do-in-buenos-aires", "/aaa/bbbb/argentina/buenos-aires"
r = RewriteRule.find_by_short_uri params[:route]
r ? redirect_to(r.uri + "?rewrite=" + r.short_uri) : raise(RoutingError) # o lo que tengas que hacer con rutas que no enconstras en la bd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment