title: Rails Advanced Search not returning desired results
body: <p>This is my first time implementing an advanced search. I'm emulating pet finder, but for dogs and want the search functionality to be similar to that of pet finders search for pets. My desired outcome is to have the user input their desired preferences as to what kind of dog (breed, age, gender, location, etc.) they are looking for and when they click on search, it redirects and renders their desired dog. I'm not getting an error at all just not getting the desired results. </p>
  
  <p>Please let me know if you need additional information.</p>
  
  <p>I want to add that if I take out the if statement in searchs_controller.rb and just have: <code>@dogs = Dog.search(params[:location], params[:breed], params[:age], params[:gender]).all</code> then it gives me this error:</p>
  
  <pre><code>ActionView::Template::Error - PG::UndefinedFunction: ERROR:  operator does not exist: integer ~~ unknown
  LINE 1: ...n LIKE '%92603%' AND breed LIKE '%corgi%' AND age LIKE '%Bab...
                                                               ^
  HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
  : SELECT "dogs".* FROM "dogs" WHERE (location LIKE '%92603%' AND breed LIKE '%corgi%' AND age LIKE '%Baby%' AND gender LIKE '%female%'):
  </code></pre>
  
  <p>app/controllers/searchs_controller.rb</p>
  
  <pre><code>class SearchsController &lt; ApplicationController
  
      def index
        if params[:search]                                                                                                                                    
           @dogs = Dog.search(params[:location], params[:breed], params[:age], params[:gender]).all
        else
            @dogs = Dog.all.order("age ASC")
         end
      end
  end
  </code></pre>
  
  <p>app/models/dog.rb</p>
  
  <p>Before:</p>
  
  <pre><code>class Dog &lt; ApplicationRecord
  
    def self.search(location, breed, age, gender)                                                                                                           
      return all unless location.present? || breed.present? || age.present? || gender.present?
      where(['location LIKE ? AND breed LIKE ? AND age LIKE ? AND gender LIKE ?', "%#{location}%", "%#{breed.downcase}%", "%#{age}%", "%#{gender.               downcase}%"])
    end
  
  end
  </code></pre>
  
  <p>After: </p>
  
  <pre><code>def self.search(location, breed, age, gender) 
      return all unless location.present? || breed.present? || age.present? || gender.present?
      where('location @@ ? AND breed @@ ? AND age = ? AND gender @@ ?', location, breed.downcase, age, gender.downcase)
    end
  </code></pre>
  
  <p>app/views/searchs/index.html.erb</p>
  
  <pre><code>&lt;div class="doge-info"&gt;
     &lt;% @dogs.each do |d| %&gt;                                                                                                                                 
        &lt;h2&gt;Meet: &lt;%= d.name %&gt;&lt;/h2&gt;
        &lt;h4&gt;&lt;%= d.name %&gt; is a &lt;%= d.breed %&gt;&lt;/h4&gt;
  
        &lt;% if d.gender.titleize == "Female" %&gt;
          &lt;h4&gt;She is &lt;%= d.age %&gt; years old.&lt;/h4&gt;
        &lt;% else %&gt;
          &lt;h4&gt;He is &lt;%= d.age %&gt; years old.&lt;/h4&gt;
        &lt;% end %&gt;
  
     &lt;% end %&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>app/views/dogs/_form.html.erb</p>
  
  <p>Updated 03/08:</p>
  
  <pre><code>&lt;div class="search-for-dogs-form"&gt;
    &lt;%= form_tag searchs_index_path, method: "get", class: "search-dogs" do %&gt;
  
      &lt;div id="form-searching-for-dogs"&gt;
  
        &lt;div class="location"&gt;
          &lt;% label_tag :location, class: "location-label" %&gt;
          &lt;%= number_field_tag :location, params[:location], max: 0..5, placeholder: "Zip Code", class: "zip-code-area" %&gt;
        &lt;/div&gt;
  
        &lt;div class="dog-breed"&gt;
          &lt;% label_tag :breed, class: "breed-label" %&gt;
          &lt;%= text_field_tag :breed, params[:breed], placeholder: "Breed", class: "breed-text-field" %&gt;
        &lt;/div&gt;
  
        &lt;div class="dog-age"&gt;
          &lt;p class="age-name"&gt;Choose an Age Range:&lt;/p&gt;
          &lt;%= radio_button_tag :age, "#{0..2}" %&gt;
          &lt;%= label_tag :age_baby, "0-2 years", class: "age-baby" %&gt;
          &lt;%= radio_button_tag :age, "#{3..5}" %&gt;
          &lt;%= label_tag :age_young, "3-5 years", class: "age-young" %&gt;
          &lt;%= radio_button_tag :age, "#{6..8}" %&gt;
          &lt;%= label_tag :age_adult, "6-8 years", class: "age-adult" %&gt;
        &lt;/div&gt;
  
        &lt;div class="dog-gender"&gt;
          &lt;% label_tag :gender, class: "gender-label" %&gt;
          &lt;%= text_field_tag :gender, params[:gender], placeholder: "Dog Gender", class: "gender-text-field" %&gt;
        &lt;/div&gt;
  
        &lt;div class="submit-button-for-search"&gt;
          &lt;%= submit_tag "Search for Dogs", name: nil, class: "dog-search-submit-button" %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>app/config/routes.rb</p>
  
  <pre><code>   devise_for :admins
     root to: 'homepages#index'
  
     resources :dogs, only: [:index, :show]
     get "searchs/index"
  
     namespace :admin do
       resources :dogs
     end
  </code></pre>
  
  <p>db/schema.rb</p>
  
  <pre><code>create_table "dogs", force: :cascade do |t|
      t.string "name"
      t.integer "age"
      t.string "breed"
      t.string "gender"
      t.boolean "adoptable"
      t.datetime "post_date"
      t.string "color"
      t.string "size"
      t.string "birth_date"
      t.string "photo"
      t.string "location"
    end
  </code></pre>