I am a complete newbie to programming. All I have to go on at this
point is the Agile book from Pragmatic Prog. and all the reading I have
been doing on the net.
I am looking (begging!) for some help with the following:
I have a form that collects multiple parameters in a view template, as
The data entered by the user is then sent to the employee controller
file which holds the following:
empno = params[:empno]
title = params[:title]
givname = params[:givname]
surname = params[:surname]
@employees = Employee.find(:all,:conditions => ["employee_number =
and title = ?
and given_name = ?
and surname = ?",
This all works fine if the user enters a value into each one of the four
fields in the form, but if one of the fields is left blank (eg
given_name), I get zero results, even if the data entered into all
fields other than given_name does match with an existing record.
From my limited knowledge, this seems to be happening because the SQL
query constructed tries to find a record where value = null for the
field that was left blank (eg given_name).
How can I amend the find method to only bring field conditions into the
query construct if the user has entered values against those fields?
I have spent a long time trying to figure this out, but just cannot seem
to come up with a solution.
Any help would be very much appreciated.