c8b9833dee
Ooh, this one was nasty, and only one symptom ever got noticed: 1. Pick "Occupies: Collar" in Advanced Search. You get the text query "occupies:necklace". 2. And, if you try to do "occupies:collar" even in text-based search, you *also* get the results from "occupies:necklace" mixed in with the correct results. The trick is that, in Spanish, zone 24 (necklace) is named "collar", as is zone 27 (collar). Not sure what to do for Spanish, but this issue also leaked into English: we really don't want English to return results for Spanish-named zones. This is a tricky problem, though, because it'd be nice for es users to be able to type "occupies:hat". I think we'll have to do the quick fix for now, though, and just only interpret the query in the current locale.
27 lines
871 B
Ruby
27 lines
871 B
Ruby
class Zone < ActiveRecord::Base
|
|
translates :label, :plain_label
|
|
|
|
# When selecting zones that an asset occupies, we allow the zone to set
|
|
# whether or not the zone is "sometimes" occupied. This is false by default.
|
|
attr_writer :sometimes
|
|
|
|
scope :alphabetical, lambda {
|
|
with_translations(I18n.locale).order(Zone::Translation.arel_table[:label])
|
|
}
|
|
scope :includes_translations, lambda { includes(:translations) }
|
|
scope :with_plain_label, lambda { |label|
|
|
t = Zone::Translation.arel_table
|
|
includes(:translations)
|
|
.where(t[:plain_label].eq(Zone.plainify_label(label)))
|
|
.where(t[:locale].eq(I18n.locale))
|
|
}
|
|
scope :for_items, lambda { where(arel_table[:type_id].gt(1)) }
|
|
|
|
def uncertain_label
|
|
@sometimes ? "#{label} sometimes" : label
|
|
end
|
|
|
|
def self.plainify_label(label)
|
|
label.delete('\- /').parameterize
|
|
end
|
|
end
|