filtering results based on multiple criteria

What's the paradigm for providing a set of filters for search

Here's my example: I have a list of projects, and projects can be
filtered by manager, status (open, closed, in progress), start date,
etc. The filter settings are stored in the database using the
preferences plugin, which works very nicely. However, my code is
ugly, and I can't detect when a filter has be unset, which makes me
think there is a better way.


# the if statement always returns true even if show_closed_projects is
def index
  @projects = Projects.all
  if defined? params[:show_closed_projects] &&
params[:show_closed_projects] == 'on'
    current_user.write_preference(:show_closed_projects, true)
    @projects = @projects.closed # this is a named scope
    current_user.wrirte_preference(:show_closed_projects, false)

# this works -- if the preference is set, the checkbox is checked,
otherwise, it's not checked.
<div id="project-filters" style="display:none" class="options">
  <form action="/company/6/projects">
      <legend>project filter options</legend>
      <table class="vertical-columns">
          <th colspan=2>
            <input type="checkbox"
              <%=h current_user.prefers_show_closed_projects ?
"checked" : "" %>
            Show closed projects?
    <p class="button-container">
      <%= submit_tag "save filters" %>
      <%= link_to "cancel" %>

...projects listed here...