0
這裏的模型mongoid嵌入文檔標準,不承認
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的新手,並試圖自己解決問題所需的盡職調查,但我很難過。