title: ruby on rails - Search form with select_tag
body: <p>I have 2 models, Post and Location, where location has_many posts and post belongs_to location. I want to make a search function with 3 conditions. With the following code it did not return any thing in my testing.</p>
  
  <p>View
  search.html:</p>
  
  <pre><code>&lt;%= form_tag search_posts_path, :method =&gt; 'get' do %&gt;
      &lt;p&gt;
          &lt;%= text_field_tag :title, params[:title] %&gt;
          &lt;%= text_field_tag :company, params[:company] %&gt;
          &lt;%= select_tag :location_id, options_from_collection_for_select(Location.all, :id, :name, params[:location_id]), include_blank: true %&gt;
          &lt;%= submit_tag "Search", :name =&gt; nil %&gt;
      &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Controller
  post_controller.rb:</p>
  
  <pre><code>  def search
      title = params[:title]
      company = params[:company]
      location_id = params[:location_id]
      @posts = Post.search(title, company, location_id)
    end
  </code></pre>
  
  <p>Model Post.rb</p>
  
  <pre><code>def self.search(title, company, location_id)
      return scoped unless title.present? || company.present? || location_id.present?
  where(['title LIKE ? AND company LIKE ? AND location_id = ?', "%#{title}%", "%#{company}%", "%#{location_id}%"])
  end
  </code></pre>