[" saved_by = ? AND employee_ID = ? ", session[:employee_id],
delEmp.to_i])
crew.destroy
end #if
end #for
It seems like there should be a way to do this with a single DB query
instead of using 2. Any suggestions?
Maybe this? The find will only return an object if one matches the
conditions, and your conditions seem to be the same from count to find,
so if we find it, destroy. Wrap it in a begin/rescue/end in case we
dont’ find it and it complains about that, the rescue will shut it up.
for delEmp in employ
begin
ListCrew.find(:first,
:conditions => [“saved_by = ? AND employee_ID = ?”,
session[:employee_id],
delEmp.to_i]).destroy
rescue
nil
end
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.