Skip to content

Instantly share code, notes, and snippets.

@pollingj
Created July 25, 2010 09:40
Show Gist options
  • Save pollingj/489452 to your computer and use it in GitHub Desktop.
Save pollingj/489452 to your computer and use it in GitHub Desktop.
def filter_url_helper(filter_key, filter_value)
product_group_query = params[:product_group_query] != nil ? Array.new(params[:product_group_query]) : nil
if product_group_query == nil
return "/t/#{params[:id].join('/')}/s/#{filter_key}/#{filter_value}"
end
if product_group_query.index(filter_key) == nil
return "/t/#{params[:id].join('/')}/s/#{product_group_query.join('/')}/#{filter_key}/#{filter_value}"
else
product_group_query[product_group_query.index(filter_key)+1] = filter_value
return "/t/#{params[:id].join('/')}/s/#{product_group_query.join('/')}"
end
end
#view code
<dl>
<dt>Price Bands</dt>
<dd><a href="<%=filter_url_helper('price_between', '0,50') %>">less than £50</a></dd>
<dd><a href="<%=filter_url_helper('price_between', '50,100') %>">£50 - £100</a></dd>
<dd><a href="<%=filter_url_helper('price_between', '100,500') %>">£100 - £500</a></dd>
</dl>
<dl>
<dt>Brands</dt>
<% @brands.each do |brand| -%>
<% brand.root.children.each do |taxon| %>
<dd><a href="<%=filter_url_helper('in_taxon', taxon.name) %>"><%= taxon.name %></a></dd>
<% end -%>
<% end -%>
</dl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment