这是模型
class Scammer
include Mongoid::Document
field :email_used
field :phone_used
field :name_used
field :first_logged, type: DateTime
field :last_scam_attempt, type: DateTime
field :checked, type: Integer, default: 0
field :scams_count, type: Integer
field :common_commodity
field :status
embeds_many :reports
embeds_many :reporters
embeds_many :requestors
end
class Report
include Mongoid::Document
embedded_in :scammer
field :reported, type: DateTime
field :posed_as
field :encountered_through
field :commodity
field :details
field :logged_by
end
class Reporter
include Mongoid::Document
embedded_in :scammer
field :reporter_ip
field :captured, type: DateTime
end
class Requestor
include Mongoid::Document
embedded_in :scammer
field :requestor_ip
field :captured, type: DateTime
end
现在这是我用来尝试对这些模型做某事的代码
# It's an email address,
if Scammer.where(email_used: @search_term).exists?
if not Scammer.requestors.where(requestor_ip: request.remote_ip).exists?
Scammer.requestors.create(requestor_ip: request.remote_ip, captured: DateTime.current()).save
end
@return = Scammer.where(email_used: @search_term).to_json
else
# No entry found. We should now add this to the database as a search
@newscammer = Scammer.new(email_used: @search_term, checked: 1, first_logged: DateTime.current(), status: "Seems Legit")
@newscammer.requestors.create(requestor_ip: request.remote_ip, captured: DateTime.current())
@newscammer.save
@return = "{ 'message' : 'Email added to database' }"
end
一切正常,直到这条线
Scammer.requestors.where(requestor_ip: request.remote_ip).exists?
此行导致此错误
undefined method `requestors' for Scammer:Class
我已经浏览了 Mongoid.org 以及此处和其他板上的各种其他帖子,但我找不到从 Scammers 访问嵌入式 Requestor 元素的方法。我是 Ruby 的新手,并试图自己解决问题所需的尽职调查,但我很难过。