Created
March 7, 2018 23:07
-
-
Save eatoncw/7690f4c6321db9ea92184216fad6809a to your computer and use it in GitHub Desktop.
eg rails helper using request params and data set to create radio buttons for product filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ProductFiltersDataHelper.furniture_types | |
[ | |
{name: "all", types: "all"},{name: "sofas and loveseats", types: "!table sofa couch sectional loveseat settee"}, | |
{name: "wardrobes", types: "wardrobe armoire chifforobe"},{name: "buffets", types: "buffet sideboard credenza"}, | |
{name: "chairs and stools", types: "chair armchair recliner stool rocker"},{name: "tables", types: "table sidetable"}, | |
{name: "beds", types: "!table bed"},{name: "desks", types: "desk"}, | |
{name: "bookcases and shelves", types: "!desk bookcase shelves"},{name: "cabinets", types: "cabinet"}, | |
{name: "mirrors", types: "mirror"} | |
] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include ProductFiltersDataHelper #file containing subcategories | |
def product_type_filter | |
html = "<fieldset class='sales-filters form-group mb-2' id='filter-by-type'>" | |
title = "<p class='mb-half'>Type</p>" | |
case request.params[:category] | |
when | |
"furniture" | |
category_html = return_product_filter_radios(ProductFiltersDataHelper.furniture_types) | |
when | |
"lighting" | |
category_html = return_product_filter_radios(ProductFiltersDataHelper.lighting_types) | |
when | |
"appliances" | |
category_html = return_product_filter_radios(ProductFiltersDataHelper.appliance_types) | |
else | |
category_html = "" | |
title = "" | |
end | |
html += title + category_html + "</fieldset>" | |
html.html_safe | |
end | |
def return_product_filter_radios(categories) | |
category_html = "" | |
categories.each_with_index do |cat,i| | |
category_html += "<div class='form-check'> | |
<label class='form-check-label'> | |
<input type='radio' class='small form-check-input' name='type' id='type-radios-#{cat[:name]}' value='#{cat[:types]}' #{'checked' if i == 0}> | |
#{cat[:name]} | |
</label> | |
</div>" | |
end | |
return category_html | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment