Forum: Ruby on Rails filter a list

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Santiago Hirschfeld (Guest)
on 2006-02-16 19:26
(Received via mailing 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

here's what i put in my controller

if @params[:filter].nil?
  @params[:filter] = { 'sent' => "1"}

... 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 %>

<table> ..... </table>

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?
Santiago Hirschfeld (Guest)
on 2006-02-17 06:10
(Received via mailing list)
anyone? please
Tom M. (Guest)
on 2006-02-17 08:25
(Received via mailing list)
Look at Enumerable.grep

-- Tom M.
Santiago Hirschfeld (Guest)
on 2006-02-17 16:28
(Received via mailing list)
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. <removed_email_address@domain.invalid>:
Ammon C. (Guest)
on 2006-02-18 03:17
(Received via mailing list)
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.
Santiago Hirschfeld (Guest)
on 2006-02-18 07:19
(Received via mailing list)
thanks, that did it

2006/2/17, Ammon C. <removed_email_address@domain.invalid>:
This topic is locked and can not be replied to.