I am trying to add facet navigation to my website, without the use of Gems.
I have this in my view
<% facets.each do |keyword, values| %>
<h4 class="facet-heading">
<%= keyword.gsub('_', ' ').titleize %>
</h4>
<ul class="facets">
<% values.each do |value| %>
<li>
<%= link_to controller: "catalog13",
action: "mgroup", id: params[:id].gsub('_', ' '),
lv2: params[:lv2].gsub('_', ' '),
pagetype: params[:pagetype], keyword: keyword,
value: value.value do %>
<%= image_tag "m13/checkbox_unselected.jpg", size: "12x12" %>
<%= value.value %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
and this in my controller
def facets
if params[:id] && params[:lv2]
catalogs = current_user.customer.catalog_list.split(",")
groupcodes = Matrixindex
.where(
catalog_id: catalogs,
idesclv1: params[:id].gsub('_', ' '),
idesclv2: params[:lv2].gsub('_', ' '),
pagetype: "C"
)
.group(:groupcode)
.map{|product| product.groupcode}
pmets = Matrixpmet.select("keyword, value").where(groupCode: groupcodes).group(:value)
pmets = pmets.group_by {|pmets| pmets.keyword}
pmets.delete("Description")
pmets.delete("Manufact. Part No.")
@facets = pmets
end
end
helper_method :facets
I am trying to make it so when the link is clicked the image changes to a ticked checkbox and the keyword and value is added to the url, if the link is clicked again I would like it so it removes from the urls params and the image changes to an empty check box. I am also trying to get it so if you click more than one link it adds to the url’s params too but everything I am trying is overwriting the already exisitng keyword and value params in the url.
I am trying to get it to work like the Amazon one does.
Any help is greatly appreciated.