Skip to content

Instantly share code, notes, and snippets.

@rgould
Created June 27, 2012 19:22
Show Gist options
  • Save rgould/3006199 to your computer and use it in GitHub Desktop.
Save rgould/3006199 to your computer and use it in GitHub Desktop.
oh crap format
# @current_region
def show
if @current_brand == Brand.gaggleup
@deals = Deal.select('distinct deals.*').active.approved.in_region_incl_parents(@current_region).started.order("starts_at desc").limit(15)
@header_title = t('_gup', :default => 'GaggleUp')
@deals = @deals.delete_if do |deal|
true unless check_for_exclusive_deal_access(deal, current_user)
end
render 'show_gaggleup'
else
# check if user is authorized to view a deal that is not approved or hasn't started yet
if !@deal.nil? && (!@deal.approved || !@deal.has_started?)
unless !current_user.nil? && (current_user.is_admin? || current_user.business.try(:id) == @deal.business.id)
render_404
end
end
#check if user user is authorized to view a deal that is for exclusive users
unless @deal.nil? || check_for_exclusive_deal_access(@deal, current_user)
render_404
end
if @deal.nil?
Deal.live_by_brand(current_brand, @current_region).each do |chkdeal|
@deal = chkdeal and break if check_for_exclusive_deal_access(chkdeal, current_user)
end
end
if @deal
@header_title = @deal.title_page.present? ? @deal.title_page : @deal.title
@time_remaining = @deal.ends_at.to_i - Time.now.to_i
@deal_items_to_tip = (@deal.tipped?) ? 0 : @deal.items_to_tip
@deal_quantity_remaining = @deal.quantity_available
@deal_is_quantity_displayed = @deal_quantity_remaining != nil && @deal.display_low_stock != nil && @deal.display_low_stock > 0 && @deal_quantity_remaining <= @deal.display_low_stock
@deal_quantity_remaining = @deal_is_quantity_displayed ? @deal_quantity_remaining : 0;
@deal_is_ended = @deal.has_ended?
@deal_is_sold_out = @deal.sold_out?
@deal_is_ended_or_sold_out = @deal_is_ended || @deal_is_sold_out
@deals = Deal.live_by_brand(current_brand, @current_region).where({:id.not_eq => @deal[:id]}).limit(3)
@deals = @deals.delete_if do |deal|
true unless check_for_exclusive_deal_access(deal, current_user)
end
@business_locations = BusinessLocationDecorator.decorate(@deal.physical_locations(@current_region).order(:address))
end
@deals ||= []
@deals = DealDecorator.decorate(@deals)
@time_remaining ||= 0
if params.has_key? 'checkout_timeout_notice'
flash[:notice] = params['checkout_timeout_notice']
end
end
@deals ||= []
@deals = DealDecorator.decorate(@deals)
@time_remaining ||= 0
if params.has_key? 'checkout_timeout_notice'
flash[:notice] = params['checkout_timeout_notice']
end
channel = @current_brand.slug
render 'show_' + channel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment