palexander (owner)

Revisions

gist: 225437 Download_button fork
public
Public Clone URL: git://gist.github.com/225437.git
Embed All Files: show embed
redirect_controller.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# The redirect controller allows for routes-based redirects
# as we move old content to new URL locations.
 
class RedirectController < ApplicationController
  def index
    if params[:url] # We were provided with a url to redirect to
      params_string = ""
      # Trigger to switch the placeholders
      first_param = true
      # Loop through the given params, ignore ones we know about or are provided by default
      params.each do |param, value|
        if !param.eql?("url") && !param.eql?("action") && !param.eql?("controller")
          seperator = first_param ? "?" : "&"
          first_param = false
          params_string += seperator + param + "=" + value
        end
      end
      # Redirect with params intact
      redirect_to params[:url] + params_string, :status=>:moved_permanently
      return
    else # Default redirect to the home page
      redirect_to "/", :status=>:moved_permanently
    end
  end
end