Skip to content

Instantly share code, notes, and snippets.

@mikldt
Created December 30, 2009 04:51
Show Gist options
  • Save mikldt/265848 to your computer and use it in GitHub Desktop.
Save mikldt/265848 to your computer and use it in GitHub Desktop.
class ProductionsController < ApplicationController
#...
# GET /productions/1
# GET /productions/1.xml
# Alternately, old URLs:
# GET /productions/2009/11/23/Hyphenated-Title
def show
# Identify production if we got here by /month/day/year/slug URL,
# e.g. links generated for the old RPI TV website.
# We will not support production.php?prodid=123 due to server configs.
if params[:year] && params[:month] && params[:day]
possibilities = Production.find_all_by_release_date(
params[:year].to_s + '-' +
params[:month].to_s + '-' +
params[:day].to_s
)
if possibilities.size == 1
# Only one. Got it!
@production = possibilities.first
elsif possibilities.size > 1
# Not conclusive. We'll apply the transformation that was used
# for the old php-based rpitv website to see if we can make an ID.
possibilities.each do |prod|
old_slug = prod.title.gsub(/[^A-Za-z0-9]+/,'-')
if params[:slug]==old_slug
#This matches.
@production = prod
break
end
end
end
end # 0 results means we just try id lookup below.
# Go ahead with the normal identification if we haven't identified
# the production some other way.
if @production.nil?
@production = Production.find(params[:id], :include => :category)
end
# Redirect to the proper URI, if we're not there already.
# Stop rendering if the redirect is requested.
ensure_uri production_path(@production) or return
# ... Continue on to rendering, etc.
end
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment