RoR - Search Forms with Checkboxes, display appropriate results

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%>
        <p>
            <b>Location:</b>
            <%= text_field_tag :search, params[:search]%><br />

            <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|%>

<div id="name">
<h2> <%= link_to hotel.name, hotel %> </h2>
</div>

   <div id="description">

       <%= truncate(hotel.description, :length => 20) %>
   </div>

<%end%>

Thanks in advance, I can't comprehend how to it with checkboxes when
they can have multiple results.

Maybe this could be your answer:

def self.search(params)
if params
query = “SELECT * FROM Hotel where city LIKE ‘#{params[:search]}’ OR name LIKE ‘#{params[:search]}’”

query+= “AND rating = #{params[:rating]}” if params[:rating]

@hotels = find_by_sql(query)
arel
else
@hotels = Hotel.all
end
end

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 />

       <%= submit_tag "Search", :name => nil%>

   </p>

<%end%>

<% @hotels.each do |hotel| %>

[hotel.name](http://hotel.name)

facilities

<% hotel.facility do |facility|%>

<% end %>

<% end %>

aash dhariya wrote in post #1057118:

Maybe this could be your answer:

def self.search(params)
   if params
      query = "SELECT * FROM Hotel where city LIKE '#{params[:search]}'
OR
name LIKE '#{params[:search]}'"
      query+= "AND rating = #{params[:rating]}" if params[:rating]
      @hotels = find_by_sql(query)
     arel
   else
     @hotels = Hotel.all
   end
end

Unforunatly the code above does not work. Its a logical error.

And:

  <% @hotels.each do |hotel| %>
     <p>hotel.name</p>

Isn't showing any hotels at all, even with the search empty.
All I altered from your code was

query = "SELECT * FROM Hotel

to
query = "SELECT * FROM hotels

which is the name of the table.

If anyone has anymore tips, I would really appreciate it.

Best Regards