我收到一个奇怪的错误。我有客户和消息....客户有_许多消息.. 和消息属于_给客户 客户有一个电话栏,一条消息有一个到栏。下面的代码假设获取当前客户 ID 并获取电话列,然后根据to列查找与电话匹配的所有消息。然后使用客户 ID 更新所有消息。
我收到这个错误,我没有看到问题。有人能告诉我我做错了什么吗?每个循环都会触发错误。我试图检查@foundmessage_all 但这不起作用。
PG::SyntaxError: ERROR: syntax error at or near "to" LINE 1: SELECT
"messages".* FROM "messages" WHERE (to = '2081234567'... ^ : SELECT
"messages".* FROM "messages" WHERE (to = '2081234567' )
客户/show.rb
@customer = Customer.find(params[:id])
tempphone = @customer.phone
@foundmessage_all = Message.where('to = ? ', tempphone)
if @foundmessage_all != nil
@foundmessage_all.each do |t|
t.update_attribute(:customer_id, @customer.id)
end
else
#other stuff
end
更改为以下语句:
@foundmessage_all = Message.where(to: tempphone)
如果这不能解决问题,请发布完整的堆栈跟踪。
您也应该检查present?
上@foundmessage_all
,而不是!= nil
if @foundmessage_all.present?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句