Skip to content

Instantly share code, notes, and snippets.

@h-lame
Forked from tomlea/gist:279962
Created January 18, 2010 12:12
Show Gist options
  • Save h-lame/279963 to your computer and use it in GitHub Desktop.
Save h-lame/279963 to your computer and use it in GitHub Desktop.
class SomeController
before_filter :find_product
before_filter :sanitise_segment
def show
@product.reviews.for_segment(@segment).order_by(sort_order)
end
def show_extended_detail
@product.reviews.for_segment(@segment).order_by(sort_order)
end
protected
def sort_order
# Google was indexing "random" search orders, it parsed our javascript, badly.
SORT_METHODS[params[:sort_order]] or raise_redirect_to(@product, :status => 301)
end
def find_product
@product = …
end
def sanitise_segment
@segment = params[:segment]
@segment = @segment.to_sym if %w[all other].include?(@segment)
@segment = nil if @segment == :all
# Bad or expired segments need 301ing
redirect_to(@product, :status => 301) if @segment === String and [email protected]?(segment)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment