You are asking about some basic programming issues, so this is
targeted that way.
You will do well to implement session variables here. You will need to
capture the user's selected options in the session and reflect those
choices back to the form when the page is redrawn. You can use the
same form as the original search. You can have separate session
variables for each parameter or collect them in a hash. It may be
easier to work with separate variables, depending on your experience.
Use whatever controller you want to analyze the selected options and
build or select which query to use.
For those who have never done this, suppose one of the options was an
integer for size. You would pass params[:option_a] or params[:search]
[:option_a] to your controller. In the target action, you would set:
# setting a session variable from form input; since all
parameters are of the form string,
# you need to convert it if you want an integer. This is done for
illustrative purposes here,
# as a string data type could just as well be used in the
database unless you were doing some math
# operation in the database. If you were passing an id, you would
# to make sure it was an integer when passed to the query
session[:option_a] = params[:search][:option_a].to_i
Then you would run the appropriate query such as:
# using '?' makes SQL injection attacks more difficult
@filter = Product.find_by_sql(["SELECT * FROM products WHERE
In the view containing the form, you would make session[:option_a]
available to the appropriate input:
<% size = ''
unless nil == session[:option_a]
size = session[:option_a].to_s # it would typically work here
without the conversion method
<input type=text name='option_a' value=<%= size -%> > ...or the
rails form_helper equivalent.
This allows you to use the same form and to remember the previous
input through each iteration.
You will also want to be familiar with input validation techniques to
handle mistakes and input from users who might try to use your site in
unintended ways. You will need to use HTMLEntities for text values,
even if you use an option list to submit data:
# the name for the session variable and the parameter don't have
to match, but it makes programming easier
session[:color] => HTMLEntities.encode_entities(params[:product]
[:color], :basic, :named)
and in the form:
<% user_text = ''
unless nil == session[:color]
user_text = HTMLEntities.decode_entities(session[:color])
You can define searches in your model or controller (or view), but
searches should be called from the controller. If you try to define a
search in the model using session[:option_a], it will not work.
This does not answer all your questions, but maybe will help someone.