I have a form that allows me to search a hotel by city or name and by
rating through radio buttons. It all works.
However, my hotel model has_one :facility, this facility model is
composed by several boolean fields (for example, roomservice:boolean
restaurant:boolean and so on)
The question is, I want to add checkbox fields for each facility I have
and in the search form, when the user selects it and presses Search, it
should only display the hotels which have those facilities. I’ve
searched but i can’t put it to work.
My hotel model:
def self.search(params)
if params
arel = where('city LIKE ? OR name LIKE ?', "%#{params[:search]}%",
“%#{params[:search]}%”)
arel = arel.where(‘rating = ?’, params[:rating]) if
params[:rating].present?
(what to put here?)
arel
else
all
end
end
My index view:
<%= form_tag hotels_path, :method =>‘get’ do%>
Location:
<%= text_field_tag :search, params[:search]%>
<b>Rating:</b><br />
<%= radio_button_tag :rating, '5'%>5 Stars<br />
<%= radio_button_tag :rating, '4'%>4 Stars<br />
<%= radio_button_tag :rating, '3'%>3 Stars<br />
<%= radio_button_tag :rating, '6'%>Hostels<br />
<b>Facilities:</b>
(what to put here?)
<%= submit_tag "Search", :name => nil%>
</p>
<%end%>
…
<% @hotels.each do |hotel|%>
<%= link_to hotel.name, hotel %>
<%= truncate(hotel.description, :length => 20) %>
<%end%>
Thanks in advance, I can’t comprehend how to it with checkboxes when
they can have multiple results.