我在Rails中使用这个MiniTest遇到了问题。
<div class="ftralert ftralert-warning">
<div>
<i class="glyphicon glyphicon-lock" style="font-size:24px;">Icon</i>
</div>
<div>
This ORDER FORM is provided in a secure environment and to help protect against fraud your current IP address (<strong>223.187.232.6</strong>) is being logged.
</div>
</div>
输出:
#device_test.rb
require 'test_helper'
should have_one(:vendor).through(:hardware)
end
根据我从多个来源收集的信息
我的问题是我没有正确建立直通关系,但是从我的收集中看来这是正确的。
Error:
DeviceTest#test_: Device should have one vendor through hardware. :
NoMethodError: undefined method `class_name' for nil:NilClass
然后它导致认为拐点存在问题,但是我在控制台中签到,并且我相信#models/device.rb
class Device < ApplicationRecord
belongs_to :site
belongs_to :hardware
has_one :vendor, through: :hardware
end
#models/hardware.rb
class Hardware < ApplicationRecord
has_many :devices
belongs_to :vendor
end
#models/vendor.rb
class Vendor < ApplicationRecord
has_many :hardwares
has_many :devices, through: :hardwares
end
,hardware
和device
具有正确的复数形式。
非常感谢您提供任何纠正此错误的帮助。