嗨,这有点微不足道,但我无论如何也想不出该在哪里做调整。我有一个LoanApplication模型和一个如下的传输模型:
class LoanApplication < ActiveRecord::Base
before_save :populate_guid
belongs_to :user
has_one :loan, -> { where loan: true }, as: :transferable
has_one :repayment, -> { where repayment: true }, as: :transferable
validates_uniqueness_of :guid
private
def populate_guid
if new_record?
while !valid? || self.guid.nil?
self.guid = SecureRandom.random_number(1_000_000_000).to_s(36)
end
end
end
end和
class Transfer < ActiveRecord::Base
belongs_to :transferable, polymorphic: true
belongs_to :user
validates_presence_of :transferable_id,
:transferable_type,
:user_id,
:amount,
:password
end为什么LoanApplication.first.loan会给我以下错误信息
LoanApplication Load (1.1ms) SELECT "loan_applications".* FROM "loan_applications" ORDER BY "loan_applications"."id" ASC LIMIT 1
NameError: uninitialized constant LoanApplication::Loan感谢大家的真知灼见。谢谢
发布于 2015-10-22 10:13:17
我认为Application是一个保留字。尝试重命名LoanApplication?
发布于 2015-10-22 15:46:40
这是微不足道的,我只需要添加class_name: "Transfer"就可以让一切正常工作。-__-‘
https://stackoverflow.com/questions/33270956
复制相似问题