samedi 11 avril 2015

Sunspot rails search. Working with range price

I' trying to use a Sunspot search gem and want to realize a price range search. But don't understand how exactly?


So in my item.rb i have



class Item < ActiveRecord::Base
#...
searchable do
text :title, :boost => 2
text :description
double :price
end

#...
end


In items_controller.rb



#...
def index
@search = Item.search do
fulltext params[:search]
with(:price) #.between ???
end
@items = @search.results.paginate(page: params[:page])
end

#...


In items/index.html.erb



<form>
<div class="form-group">
<%= form_tag index_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search], placeholder: 'what are you looking for?', class: "form-control"%>
<table class="table">
<tr>
<td><%= text_field_tag :price #how to setup a min_price?%></td>
<td><%= text_field_tag :price #how to setup a mazprice?%></td>
</tr>
</table>
<div class="btn button">
<%= submit_tag "search", :title => nil, class: "btn btn-default" %>
</div>
<% end %>
</div>
</form>


What could I do to set a range for price searching (min and max price parameters) in my controller and views? Thanks for help


Aucun commentaire:

Enregistrer un commentaire