I would appreciate a little help with use of :condition
I hav ethe following code in a controller file:-
def listbyparam if params[:department_id] != '' conditions = ["department_id = ?",
if params[:status] != ‘’
conditions = [“Status = ?”, params[:status]]
@risksfound = Risk.find(:all, :conditions => conditions)
User either clicks a link that passes a department parameter through or
a link that passes a status parameter. I then load the condition field
and retrieve records based on it.
What actually happens is that with the above code; if I send a status
through it works fine but if I send a department through it finds
nothing. However if I reverse the two if statments - putting the status
one first and then department, the department search will then work but
the status returns nothing.
It seems that whichever is the 2nd IF statement will blank the
‘condition’ field even if its parameter is passed through as blank and
the condition field has been loaded with a value by the 1st IF
Can someone please suggest a better syntax for me to load the condition
field depending on which parameter I click to pass through to the
Any help - much appreciated.