Created
November 3, 2012 03:27
-
-
Save geronimod/4005700 to your computer and use it in GitHub Desktop.
Route handler
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
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