Thanks for the quick response Walter.
Rating is a text field.
"SERIALIZE" don't have it in my model, don't know what it is...will
look it up.
As you can tell by the method name "checkBoxTest" I'm testing the
feature one check box at a time, but
you make a good point about using LIKE, IN to compare. I will try
that.
I meant to use IN rather than LIKE. LIKE is "case-insensitive text comparison" and IN is "does this value occur in that array". params[:rating] is a hash, but it will get converted to an array if you pass it into the where() method the way you are doing it. I'm still not clear why it's being converted to YAML the way it is in your LIKE clause, but I guess that's the only string-like thing that would preserve the meaning of the hash.
It's not as neat as your HAML, but the following ERB:
<p>
<%= check_box_tag "ratings[G]", 'G', (params[:ratings].include? 'G') %>
<%= label_tag "ratings[G]", "G" %>
</p>
<p>
<%= check_box_tag "ratings[PG]", 'PG', (params[:ratings].include? 'PG') %>
<%= label_tag "ratings[PG]", "PG" %>
</p>
<p>
<%= check_box_tag "ratings[R]", 'R', (params[:ratings].include? 'R') %>
<%= label_tag "ratings[R]", "R" %>
</p>
<p>
<%= check_box_tag "ratings[NC-17]", 'NC-17', (params[:ratings].include? 'NC-17') %>
<%= label_tag "ratings[NC-17]", "NC-17" %>
</p>
<p>
<%= check_box_tag "ratings", 'X', (params[:ratings].include? 'X') %>
<%= label_tag "ratings", "X" %>
</p>
<p>
<%= check_box_tag "ratings[NR]", 'NR', (params[:ratings].include? 'NR') %>
<%= label_tag "ratings[NR]", "NR" %>
</p>
Expands to this HTML:
<p>
<input id="ratings_G" name="ratings[G]" type="checkbox" value="G" />
<label for="ratings_G">G</label>
</p>
<p>
<input checked="checked" id="ratings_PG" name="ratings[PG]" type="checkbox" value="PG" />
<label for="ratings_PG">PG</label>
</p>
<p>
<input id="ratings_R" name="ratings[R]" type="checkbox" value="R" />
<label for="ratings_R">R</label>
</p>
<p>
<input id="ratings_NC-17" name="ratings[NC-17]" type="checkbox" value="NC-17" />
<label for="ratings_NC-17">NC-17</label>
</p>
<p>
<input id="ratings_X" name="ratings" type="checkbox" value="X" />
<label for="ratings_X">X</label>
</p>
<p>
<input id="ratings_NR" name="ratings[NR]" type="checkbox" value="NR" />
<label for="ratings_NR">NR</label>
</p>
And when that form is submitted, it will appear at the controller as params[:ratings]. If you pass it into your where clause, using IN instead of LIKE, you should get a query like the one I outlined. As a bonus, the checkboxes will maintain their state through a form request.
Walter