Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Created August 26, 2011 13:40
Show Gist options
  • Save urbanautomaton/1173425 to your computer and use it in GitHub Desktop.
Save urbanautomaton/1173425 to your computer and use it in GitHub Desktop.
module LayoutHelper
def page_description
begin
vars = [:@question, :@user, :@topic, :@tribe, :@challenge, :@product]
dumps = Hash[*(vars.map{|v| [v, instance_variable_get(v).inspect]}.flatten)]
description = case
when @question then @question.background
when @user && @user.bio.present? then @user.bio
when @user && @user.sports.present? then @user.sports_list
when @topic then @topic.body
when @tribe then @tribe.description
when @challenge then @challenge.description
when @product then @product.description
else "Tribesports: Connect with sports people who share your interests & create your complete sports profile. We want to inspire you to get more active and improve at your sports."
end
strip_tags(description)
rescue NoMethodError => e
new_dumps = Hash[*(vars.map{|v| [v, instance_variable_get(v).inspect]}.flatten)]
logger.info "[IMPOSSIBLE] BUG DETECTED"
logger.info "[IMPOSSIBLE] Before!"
dumps.each do |var, dump|
logger.info "[IMPOSSIBLE] #{var.to_s} => #{dump}"
end
logger.info "[IMPOSSIBLE] After!"
new_dumps.each do |var, dump|
logger.info "[IMPOSSIBLE] #{var.to_s} => #{dump}"
end
raise
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment