Skip to content

Instantly share code, notes, and snippets.

@rterbush
Created April 9, 2013 20:54
Show Gist options
  • Save rterbush/5349302 to your computer and use it in GitHub Desktop.
Save rterbush/5349302 to your computer and use it in GitHub Desktop.
Filter template for use with jbrien/spree_sunspot_search
<div class="filter" data-field="<%= filter.search_param %>">
<h4 class="filter-title"><%= t :shop_by_taxonomy, :taxonomy => filter.display_name %></h4>
<ul class="filter_choices">
<select name="<%= "s[#{filter.search_param}][]" %>" class="sidebar" size="10" multiple="true">
<% options = [] %>
<% filter.html_values.each_with_index.each do |hv, index| %>
<% options << hv[:value] %>
<% end %>
<% sortopts = options.sort %>
<% sortopts.each do |hv| %>
<% selected = params[:s][filter.search_param].include? hv.to_s if params[:s] and params[:s][filter.search_param].present? %>
<% if selected %>
<option value="<%= hv %>" selected><%= hv %></option>
<% else %>
<option value="<%= hv %>"><%= hv %></option>
<% end %>
<% end %>
</select>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment