I just started learning to use Sunspot and Solr with Rails.
I followed this RailsCast http://railscasts.com/episodes/278-search-with-sunspot, but my problem is harder. So, how can I use parameter from select_tag with sunspot to search? My code:
**MODEL**
searchable do
text :title, :content
integer :city_id
end
**VIEW**
= form_tag vacancies_path, method: "get" do
= text_field_tag :search, params[:search], placeholder: "Search", class: "form-control"
= select("city", "city_id", City.order(name: :asc).collect {|c| [ c.name, c.id ] }, {include_blank: 'Choose your city'}, class: "form-control")
= submit_tag "Search", class: "btn btn-primary"
**CONTROLLER**
def index
@search = Vacancy.search do
fulltext params[:search]
with :city_id, params[:city][:city_id]
end
@vacancies = @search.results
end
**LOGS**
Parameters: {"utf8"=>"✓", "search"=>"ruby", "city"=>{"city_id"=>"1973"}, "commit"=>"Искать"}
SOLR Request (4.0ms) [ path=select parameters={fq: ["type:Vacancy", "city_id_i:1973"], q: "ruby", fl: "* score", qf: "title_text content_text", defType: "edismax", start: 0, rows: 30} ]
It's not working. When I'm removing with :city_id, params[:city][:city_id]
everything works fine except.. city filter. Thanks in advance.