我正在尝试将给定字段与模型Header
中的其他字段进行比较。Alarm
正如您在代码中看到的,我通过 3 个不同的步骤过滤警报。前 2 个工作完美。但是,最后一个不起作用。它说:
undefined method `where' for #<Array:...
据我了解.where
是一种适用于数组的类方法。为什么在这里不起作用?我也尝试过.find_all_by
不同的东西......但无济于事。
@header = Header.find(1)
# Extracts those alarms that are ACTIVE and have something in common with the tittles
@alarmsT = Alarm.activated.where("keyword in (?)", [@header.title_es, @header.title_en, @header.title_en])
# Extracts alarms when Header has at least the same categories as an alarm
@alarmsT = @alarmsT.select do |alarm|
@header.category_ids.all?{|c| alarm.category_ids.include? c }
end
// this is the one that does NOT work
# Extract alarms which share the same location as Header.events' town
@alarmsF = []
@header.events.each do |e|
@alarmsF = @alarmsF + @alarmsT.where("alarms.location LIKE ?", e.town)
end
任何帮助发现我所缺少的东西都非常感谢。谢谢