Class: PathRewrite::PathController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/path_rewrite/path_controller.rb

Instance Method Summary collapse

Instance Method Details

#rewriteObject



4
5
6
7
8
9
10
# File 'app/controllers/path_rewrite/path_controller.rb', line 4

def rewrite
  rewrite = PathTranslation.find_by(old_path: "/#{params["path"]}") or raise ActionController::RoutingError.new("Not Found")

  Rails.logger.debug "Redirecting #{rewrite.old_path} to #{rewrite.new_path} from request #{request.url}"

  redirect_to rewrite.new_path, status: 301
end