我的示波器有什么问题,轨道上的红宝石?


scope :between, -> (sender_id,recipient_id) do
where(“(conversations.sender_id = ? AND conversations.recipient_id = ? ) OR (conversations.sender_id = ? AND conversations.recipient_id =?)”, sender_id, recipient_id, recipient_id, sender_id)
end

我不断收到一个错误,说:

warning: invalid character syntax; use ?s

我该如何解决这个问题?

您正在使用倾斜的双引号((,这不是 Ruby 中文字的有效字符串分隔符。如果您将文本复制到不用于 MS Word 等编程的编辑器中,通常会发生这种情况。有效的分度计是'"

还可以通过使用命名占位符而不是序号占位符来大大提高可读性。

scope :between, -> (sender_id,recipient_id) do
where(
"(conversations.sender_id = :s AND conversations.recipient_id = :r ) OR (conversations.sender_id = :r AND conversations.recipient_id = :s)", 
s: sender_id, r: recipient_id
)
end

你的引号不是标准的,而是一些奇怪的utf8字符,用"或"代替。错误消息非常具有误导性。一些编辑器正在使用这种格式,这种格式对 rails 无效。

最新更新