title: Rails 3 - Search, HABTM and Caterogizations
body: <p>I'm using the Advanced Search Form from RailsCasts (#111), but I want to add the possibity to search in subcategories with a collection check boxes.</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    # post_id, food_id, pet_id
  class Food &lt; ActiveRecord::Base
    # id, name
  class Pet &lt; ActiveRecord::Base
    # id, name
  class Post &lt; ActiveRecord::Base
    # id, title.
  </code></pre>
  
  <p>In my search.rb model, I tried : </p>
  
  <pre><code>posts = posts.where(food_ids: food_ids) if food_ids.present?
  </code></pre>
  
  <p>I created a new model called : Subcategorysearch.rb, exactly the same as Categoty.rb, but it only for the search request. Inside I have: post_id, food_id, pet_id. </p>
  
  <p>With or without the new model, I always get :</p>
  
  <p>ActiveRecord::StatementInvalid in Searches#show 
  SQLite3::SQLException: no such column: posts.food_ids</p>
  
  <p>Thanks by advance.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>When I create a new post, the Subcategories aren't going in the Post table, but in the Category table. I need to make the Post search working with the possibility of filtering with a collection check boxes the subcategories.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I tried a lot a things, but I think I'm kind of lost.</p>
  
  <p>The "real" problem, is to perform a search engine like the Railscasts #111 - Advanced Search Form and using something like the Railscasts #17 - HABTML Checkboxes, with the "categorizations".</p>
  
  <p>The final result I need, is, for exemple: Search a Post and be able to filter the result with checkboxes collection :</p>
  
  <pre><code>Post tile = My first post
  Food = Name 1
  Pet = Name 2
  </code></pre>
  
  <p>...</p>
  
  <p>And then, only show the Posts that contains the Title like "My first post", Food like "Name 1" or by ID, and the same for Pet.</p>
  
  <p>Again, thank you by advance for your support. </p>