Module: CompareProductsHelper
- Defined in:
- app/helpers/compare_products_helper.rb
Instance Method Summary collapse
-
#comparison_fields_for(products, properties) ⇒ Object
Returns an array with the translated names of the fields to be compared.
-
#comparison_rows_for(products, properties) ⇒ Object
Return the transposed matrix of the comparison table.
-
#product_fields_for(product, properties) ⇒ Object
Return an array with the values of the fields to be compared for the specified product.
Instance Method Details
#comparison_fields_for(products, properties) ⇒ Object
Returns an array with the translated names of the fields to be compared.
Example:
["Product", "Name", ..., "Price"]
38 39 40 41 42 43 44 |
# File 'app/helpers/compare_products_helper.rb', line 38 def comparison_fields_for(products, properties) [t('product'), t('name')].tap { |fields| properties.each { |property| fields << property.presentation } }.tap { |fields| fields << t('price') } end |
#comparison_rows_for(products, properties) ⇒ Object
Return the transposed matrix of the comparison table.
Example:
[
["Product", "product1 image", "product2 image"],
["Name", "product1 name", "product2 name"],
...
["Price", "product1 price", "product2 price"]
]
11 12 13 14 15 16 17 |
# File 'app/helpers/compare_products_helper.rb', line 11 def comparison_rows_for(products, properties) fields = [comparison_fields_for(products, properties)] products.each do |product| fields << (product_fields_for(product, properties)) end fields.transpose end |
#product_fields_for(product, properties) ⇒ Object
Return an array with the values of the fields to be compared for the specified product.
Example:
["product1 image", "product1 name", ..., "product1 price"]
25 26 27 28 29 30 31 |
# File 'app/helpers/compare_products_helper.rb', line 25 def product_fields_for(product, properties) [ link_to(small_image(product), product), link_to(product.name, product)].tap { |fields| properties.each do |property| fields << product.product_properties.find_by_property_id(property.id).try(:value) end }.tap { |fields| fields << number_to_currency(product.price) } end |