I'm trying to get simple search to work on my Rails app. I just have two selectors to chose from: (a) kind and (b) location_id. The form shows up, values selectable, params pass through in url. However, nothing shows up when I submit even if there is a something to match it. I checked in my active admin and there were places to match the search parameters.
This is my places_controller.rb
def index
@places = Place.search(params[:kind],[:location_id])
end
My place.rb
def self.search(kind, location_id)
return scoped unless kind.present? || location_id.present?
where(['kind = ? AND location_id = ?', kind, location_id])
end
and my search form _home.html.erb
<%= form_tag places_path, :method => 'get' do %>
<form class="form-inline text-center" role="form" action="/places">
<div class="form-group">
<%= label_tag :kind %>
<%= select_tag :kind, options_for_select([['beer','0'],['chocolate','1'],['cocktail','2'], ['coffee','3'], ['tea','4'], ['wine','5'], ['juice','6']]), class: "form-control" %>
/div>
<br>
<div class="form-group">
<%= label_tag :location_id %><br>
<%= select_tag :location_id, options_for_select([['Houston','0'],['San Francisco','1'],['Santiago','2'], ['Valparaiso','3'], ['Rio de Janeiro','4'], ['Milan','5'], ['Palo Alto','6'], ['Las Vegas','7'], ['New York','8'], ['San Diego','9']]), class: "form-control" %>
</div>
<br>
<br>
<div class="actions">
<span itemprop="significantLink">
<%= submit_tag 'Search', :name => nil, class: "btn btn-default" %>
</span>
</div>
</form>
<% end %>
Would appreciate any help! Have looked around on a bunch of SO/Railscasts and not sure what to do!
@placesvariable you set to the search results?