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
@projects = Projects.all
if defined? params[:show_closed_projects] &&
params[:show_closed_projects] == 'on'
@projects = @projects.closed # this is a named scope
# 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">
<legend>project filter options</legend>
<%=h current_user.prefers_show_closed_projects ?
"checked" : "" %>
Show closed projects?
<%= submit_tag "save filters" %>
<%= link_to "cancel" %>
...projects listed here...