Skip to content

Instantly share code, notes, and snippets.

@biagidp
Created November 25, 2013 01:16
Show Gist options
  • Save biagidp/7634784 to your computer and use it in GitHub Desktop.
Save biagidp/7634784 to your computer and use it in GitHub Desktop.
Adding simple scopes to search form in spree
Spree::ProductsController.class_eval do
def index
if params[:search]
[:ascend_by_master_price].each do |field|
if params[:search][field] && params[:search][field] == ''
params[:search][field] = nil
end
end
end
@searcher = build_searcher(params)
@products = @searcher.retrieve_products
end
end
<%= form_tag spree.products_path, :method => :get, :class => "search_form" do %>
<%= search_field_tag :keywords, params[:keywords], :placeholder => "Search product, artist, cause" %>
<% if params[:search] && params[:search][:ascend_by_master_price] %>
<%= hidden_field_tag "search[ascend_by_master_price]",
params[:search][:ascend_by_master_price], id: 'sort_by_field' %>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment