Skip to content

Instantly share code, notes, and snippets.

@hexgnu
Created January 17, 2012 01:25
Show Gist options
  • Save hexgnu/1623986 to your computer and use it in GitHub Desktop.
Save hexgnu/1623986 to your computer and use it in GitHub Desktop.
expose(:current_brand) do
# REFACTOR THIS PLEASE :(
if params[:current_brand_id]
session[:qp_status] = nil
session[:qp_shared_image_ids] = nil
brand_id = if current_organization.brands.exists?(:id => params[:current_brand_id])
session[:current_brand_id] = params[:current_brand_id]
params[:current_brand_id]
else
flash[:alert] = "Woops! Looks like you are trying to access something you don't have access to!"
current_organization.brands.first.id
end
current_organization.brands.where(:id => brand_id).first
elsif session[:current_brand_id]
current_organization.brands.where(:id => session[:current_brand_id]).first
else
if current_user.executive?
current_organization.brands.first
else
current_user.brands.first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment