Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View product-index-example.rb
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) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.