我有下面的代码获得原来的对象:无法从联想
account = Account.find(1)
customer = ThirdPartyAPI.retrieve("123456")
account.customers.import(customer)
而这里的导入方法:
class Customer < ActiveRecord::Base
belongs_to :account
def self.import(customer)
# I need to get the Account ID.
# Have tried `self.account.id`, but it throws this:
# NoMethodError: undefined method `account'
end
end
从这个import
方法中,我试图让主帐户ID。正如您在代码注释中看到的那样,当我尝试拨打self.account.id
时,会引发NoMethodError: undefined method 'account'
错误。
我的账户模型具有关联安装:
class Account < ActiveRecord::Base
has_many :customers
end