我从数据库中获取了一个结果列表。然后我运行了一个if语句来删除一些结果,但我不想从数据库中删除对象,只想从我提取的结果列表中删除。
那么.delete(Array.delete(object)从数据库中删除的替代方法是什么?)
def self.search(search)
if search
results = where('title LIKE ?', "%#{search}%")
results.each do |event|
if (((event.edate + event.minduration.minute) - Time.now)/60).round.to_i > 0.to_i #if the event is over? remove it from the list.
results.delete(event)
end
end
results
else
Event.all
end
end
或者,最好一开始就限制搜索结果,但我不知道如何将这两个条件组合成一行:
results = where('title LIKE ?', "%#{search}%")
((event.edate - Time.now)/60).round.to_i > 0.to_i
有人能帮我解决这个问题吗?
请尝试这样运行:-
results = where('title LIKE ? AND (event.edate - Time.now)/60).round.to_i > ?', "%#{search}%", 0.to_i)