Skip to content

Instantly share code, notes, and snippets.

@amandarae
Created August 14, 2012 19:39
Show Gist options
  • Save amandarae/3352114 to your computer and use it in GitHub Desktop.
Save amandarae/3352114 to your computer and use it in GitHub Desktop.
refactor to be scalable (ruby iteration)
def my_deals
#@orders = @current_user.orders.joins(:brand).where{|q| q.brand.slug == @current_brand.slug }.ordered.order('created_at DESC').paginate(:page => params[:page], :per_page => 10)
#other_brands = @current_user.orders.ordered.joins(:brand).includes(:brand).where{|q| q.brand.slug != @current_brand.slug }.map{|o| o.brand}.uniq
#@other_brands = BrandDecorator.decorate(other_brands)
@brands = SimpleBrand.all + NormalBrand.all
@orders = Array.new
@brands.each do |b|
@orders << @current_user.orders.ordered.joins(:brand).where{|q| q.brand.slug == b.slug}.ordered.order('created_at DESC').paginate(:page => params[:page], :per_page => 3)
end
@brands = BrandDecorator.decorate(@brands)
render 'users/orders/index'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment