Class: Caboose::Variant
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Variant
- Defined in:
- app/models/caboose/variant.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Object
Instance Methods.
- #options ⇒ Object
- #title ⇒ Object
Class Method Details
.find_by_options(product_id, option1 = nil, option2 = nil, option3 = nil) ⇒ Object
Class Methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/caboose/variant.rb', line 43 def self.(product_id, option1=nil, option2=nil, option3=nil) # Create the vars that will become the full conditions statement where = ['product_id=?'] values = [product_id.to_i] # Append option values if they exist if option1 where << 'option1=?' values << option1 end if option2 where << 'option2=?' values << option2 end if option3 where << 'option3=?' values << option3 end # Combine all the options into a single conditions statement conditions = [ where.join(' AND ') ].concat(values) # Return whatever is found return Variant.where(conditions).first end |
Instance Method Details
#as_json(options = {}) ⇒ Object
Instance Methods
77 78 79 80 81 82 83 84 85 |
# File 'app/models/caboose/variant.rb', line 77 def as_json(={}) self.attributes.merge({ :images => if self.product_images.any? self.product_images else [self.product.product_images.first] end }) end |
#options ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/models/caboose/variant.rb', line 91 def arr = [] arr << self.option1 if self.option1 && self.option1.strip.length > 0 arr << self.option2 if self.option2 && self.option2.strip.length > 0 arr << self.option3 if self.option3 && self.option3.strip.length > 0 return arr end |
#title ⇒ Object
87 88 89 |
# File 'app/models/caboose/variant.rb', line 87 def title return self..join(' / ') end |