Skip to content

Instantly share code, notes, and snippets.

@james
Last active August 29, 2015 14:07
Show Gist options
  • Save james/47501cbd92da08c41f93 to your computer and use it in GitHub Desktop.
Save james/47501cbd92da08c41f93 to your computer and use it in GitHub Desktop.
A Rails controller I wrote in 2006. This is bad code. Don't copy it.
class PagesController < ApplicationController
layout 'site'
def show
@page = Page.find_by_url(params[:id], :limit => 1)
@content = @page.content.gsub(/£/, "&pound;")
@cat = @page.category
if @cat == 'overview' or @cat == 'menu' or @cat == 'offers'
@subcat = @cat
@cat = 'restaurant'
end
end
def menu
@items = MenuItem.find(:all, :order => 'position ASC')
starters = []
mains = []
desserts = []
sstarters = []
smains = []
sdesserts = []
for item in @items
if item.category == 'starter'
if item.special?
sstarters << item
else
starters << item
end
end
if item.category == 'main'
if item.special?
smains << item
else
mains << item
end
end
if item.category == 'dessert'
if item.special?
sdesserts << item
else
desserts << item
end
end
end
@menu = [starters, mains, desserts]
@specials = [sstarters, smains, sdesserts]
@subcat = 'menu'
@cat = 'restaurant'
end
def wines
@items = Wine.find(:all, :order => 'number ASC')
reds = []
whites = []
sparklings = []
for item in @items
if item.category == 'red'
reds << item
end
if item.category == 'white'
whites << item
end
if item.category == 'sparkling'
sparklings << item
end
end
@menu = [reds, whites, sparklings]
@subcat = 'wines'
@cat = 'restaurant'
end
def quotes
@quotes = Quote.find(:all)
@cat = 'vbook'
end
def photos
@photos = Photo.find(:all, :order => 'position ASC')
@cat = 'photos'
end
def enquiries
@cat = 'enquiries'
end
def post_enquiry
@cat = 'enquiries'
Mailer.deliver_enquiry(params[:enquiry])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment