I am trying to create a dynamic query based on User inputs
if a
conditions << ["fname like (?)"]
sql_params << "abc"
end
if b
conditions << ["lname like (?)"]
sql_params << "def"
end
if c
cconditions << ["middle like (?)"]
sql_params << "xyz"
end
results = Model.where(conditions.join(' AND '), sql_params)
While the conditions get in correct syntax, the sql_params are listed as an array. This forms the below query
Model.where("fname like (?) AND lname like (?) AND middle like (?)", ["abc","def","xyz"])
while what I need is
Model.where("fname like (?) AND lname like (?) AND middle like (?)", "abc","def","xyz")
I tried several map/join etc options on the sql_params array but nothing worked.