我正在尝试搜索结果,其中一个结果的updated_at是在另一个结果的创建之后,这是我的代码在一个简短而甜蜜的版本
我收到语法错误
PG::SyntaxError: ERROR: syntax error at or near "13"
LINE 1: ...ERE ((group_id = 14 and created_at >= 2016-08-04 13:39:35 U...
^
: SELECT "chats".* FROM "chats" WHERE ((group_id = 14 and created_at >= 2016-08-04 13:39:35 UTC)) ORDER BY created_at DESC
但我不明白为什么它与时间有关?
@grouparchived = @groupread.updated_at
filter1 = "(group_id = "+@arandomthing.to_s + " and created_at >= "+@grouparchived.to_s+")"
@chats1 = Chat.where(@filter1).order('created_at DESC')
答案 0 :(得分:1)
Chat.where(group_id: @arandomthing).where('created_at >= ?', @groupread.updated_at).order('created_at DESC')
查找像你一样的字符串是灾难的一种方法,使用Rails为你提供的工具要好得多。