我收到一个奇怪的错误。我有客户和消息.... 客户has_many消息..和消息belongs_to客户 客户有电话列,并且消息中包含到列。 以下代码假设获取当前客户ID并获取手机列,然后根据手机匹配的所有消息 >到列。然后使用客户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
答案 0 :(得分:1)
更改为以下声明:
@foundmessage_all = Message.where(to: tempphone)
如果这不能解决问题,请发布完整的堆栈跟踪。
另外,您应该检查present?
上的@foundmessage_all
而不是!= nil
if @foundmessage_all.present?