From 206811a2fbfe7d138cc83cf9eb842bc22458aa45 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 28 Jan 2013 03:01:25 -0600 Subject: [PATCH] oops, deal with missing item fields better --- app/controllers/outfits_controller.rb | 2 +- app/models/closet_hanger.rb | 6 +++++- app/models/item.rb | 8 +++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index 1f0e2bf6..87de9ad6 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -47,7 +47,7 @@ class OutfitsController < ApplicationController end unless localized_fragment_exist?('outfits#new newest_items') - @newest_items = Item.newest.select([:id, :name, :thumbnail_url]). + @newest_items = Item.newest.select([:id, :thumbnail_url]). includes(:translations).limit(9) end diff --git a/app/models/closet_hanger.rb b/app/models/closet_hanger.rb index ad3dde76..dca7f13d 100644 --- a/app/models/closet_hanger.rb +++ b/app/models/closet_hanger.rb @@ -13,7 +13,11 @@ class ClosetHanger < ActiveRecord::Base validate :list_belongs_to_user - scope :alphabetical_by_item_name, joins(:item).order(Item.arel_table[:name]) + scope :alphabetical_by_item_name, lambda { + joins(:item => :translations). + where(Item::Translation.arel_table[:locale].eq(I18n.locale)). + order(Item.arel_table[:name]) + } scope :newest, order(arel_table[:created_at].desc) scope :owned_before_wanted, order(arel_table[:owned].desc) scope :unlisted, where(:list_id => nil) diff --git a/app/models/item.rb b/app/models/item.rb index 5523bd64..bcb4dfb7 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -23,7 +23,6 @@ class Item < ActiveRecord::Base cattr_reader :per_page @@per_page = 30 - scope :alphabetize, order(arel_table[:name]) scope :alphabetize_by_translations, lambda { it = Item::Translation.arel_table order(it[:name]) @@ -38,8 +37,7 @@ class Item < ActiveRecord::Base scope :sold_in_mall, where(:sold_in_mall => true) scope :not_sold_in_mall, where(:sold_in_mall => false) - scope :sitemap, select([arel_table[:id], arel_table[:name]]). - order(arel_table[:id]).limit(49999) + scope :sitemap, order([:id]).limit(49999) scope :with_closet_hangers, joins(:closet_hangers) @@ -433,7 +431,7 @@ class Item < ActiveRecord::Base all_item_ids = items.keys # Find which of these already exist but aren't marked as sold_in_mall so # we can update them as being sold - Item.not_sold_in_mall.where(:id => items.keys).select([:id, :name]).each do |item| + Item.not_sold_in_mall.where(:id => items.keys).select([:id]).each do |item| items.delete(item.id) item.sold_in_mall = true item.save @@ -460,7 +458,7 @@ class Item < ActiveRecord::Base end def spider_mall_assets!(limit) - items = self.select([arel_table[:id], arel_table[:name]]).sold_in_mall.spidered_longest_ago.limit(limit).all + items = self.select([arel_table[:id]]).sold_in_mall.spidered_longest_ago.limit(limit).all puts "- #{items.size} items need asset spidering" AssetStrategy.build_strategies items.each do |item|