Filter a list

I’d like to add some filter choices to display a list of items. These
items has some boolean fields for example, and would like to have a
checkbox at the top of the window to let me select how to filter the
list.

here’s what i put in my controller

if @params[:filter].nil?
@params[:filter] = { ‘sent’ => “1”}
end

… generate the corresponding @items array …

here’s what i did in my view

<%= form_tag :action => ‘list_items’ %>
<%= check_box ‘filter’,‘sent’ %>
<%= submit_tag ‘Filter’ %>
<%= end_form_tag %>

.....

inspecting the @params value, it seems to has a filter[:sent] key,
with the correct value (1 if checked) but the check button is always
unchecked when the page is generated.

Am i so wrong doing this? is there a better way?

anyone? please

Look at Enumerable.grep


– Tom M.

Thanks, I know i wasn’t clear enough, i’m not a native english
speaker. But my problem is not how to filter the list, my problem is
with the checkbox being always unchecked and not mantaining the state
of selected, don’t know if what i’m doing is right.
Thanks anyway.

Can someone give me a hint? please?

2006/2/17, Tom M. [email protected]:

thanks, that did it

2006/2/17, Ammon C. [email protected]:

Save the state of the checkbox when submitted in the session and then
use the value of the session variable in the tag’s definition to
maintain its value.