0
我想如果检索与Mongoid和Rails用户之间创建连接的一些信息存在,这里是代码:Mongoid查询为一个文件内关于阵列的内容
class ContactController < ApplicationController
def addNew
@newFriend = params[:username]
puts "***value of @newFriend***"
puts @newFriend
puts "***end****"
Contact.where(owner: current_user).where(friendlist: params[:username]) do |contact|
puts "***value of @contactAlreadyExists***"
puts contact
puts "***end****"
if contact == nil
Contact.find_or_create_by(owner: current_user) do |contact|
contact.push(friendlist: params[:username])
end
end
end
redirect_to "/"
end
end
控制台不显示来自
puts "***value of @contactAlreadyExists***"
puts contact
puts "***end****"
不要你的意思'Contact.where(...)每个do'? –
现在收集是空的,必须创建,如果不存在。 –
但您是否期待'Contact.where(...)确实联系我们?你将一个块交给'where',而不是一个遍历查询结果的迭代器。 –