Created
November 25, 2013 01:16
-
-
Save biagidp/7634784 to your computer and use it in GitHub Desktop.
Adding simple scopes to search form in spree
This file contains 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
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 |
This file contains 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
<%= 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