public
Created

  • Download Gist
product-index-example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class Product
STATES_INDEX_CONSTANTS = {
:active => 1,
:inactive => 2,
# ...whatever...
}
define_index do
has "CASE `products`.`state` #{ STATES_INDEX_CONSTANTS.map{|k,v| "WHEN '#{k}' THEN #{v}"}.join } END", :as => :state
end
def self.state_const(name)
STATES_INDEX_CONSTANTS[name]
end
end
 
 
 
 
# usage
Product.search("some query", :with => { :state => Product.state_const(:active) })

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.