Trying various things here to eliminate this problem. In my dyanmic search , if no search criteria is selected then all records are returned. It’s not what I want. By the way this is an observe_form. Help is greatly appreciated.
Here is the controller -
def list
category_id = params[:category_id]
state_id = params[:state_id]
term_id = params[:term_id]
city = params[:city]
title = params[:title]
pq = Position.query # I'm using the plugin CriteriaQuery
pq.category_id_in(params[:category_id]) unless(params[:category_id]|| "").empty?
pq.state_id_in(params[:state_id]) unless(params[:state_id]|| "").empty?
pq.term_id_in(params[:term_id]) unless(params[:term_id]|| "").empty?
pq.city_in(params[:city].split(",")) unless(params[:city]|| "").empty?
pq.title_in(params[:title].split(",")) unless(params[:title]|| "").empty?
pp pq
@positions = pq.find
render :partial => "positions_list", :layout => false
end
end
Here is the observe_form:# in the possibility that I can somehow enforce it here to not return any records in the event nothing is selected
# I'm also showing my partial down below
Category
State
Terms
Title
City
<%= image_tag("roller.gif",
:align => 'center',
:border => 0,
:id => "roller",
:style => "display: none;") %>
<%= observe_form “asearch”, :frequency => 0.5, :update => ‘table’, :before => “Element.show(‘roller’)”, :success => “Element.hide(‘roller’)”, :url => ‘list’ %>
Partial: <% if @positions == nil %>
<%="Enter search criteria"%>
<% elsif @positions.size == 0 %>
<%="No jobs found using current search criteria"%>
<% else %><td>Category</td>
<td>Location</td>
<td>Terms</td>
<% @positions.each do |p| %>
">
<td style="white-space: nowrap"><%= p.title %></td>
<td style="white-space: nowrap"><%= [p.category.name](http://p.category.name) %></td>
<td style="white-space: nowrap"><%= p.city %>-<%= [p.state.name](http://p.state.name) %></td>
<td style="white-space: nowrap"><%= [
p.term.name](http://p.term.name) %>
<% end %>Title |