0

嗨,这有点微不足道,但我一生都无法弄清楚在哪里进行调整。我有一个 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

所有见解都受到赞赏。谢谢

4

2 回答 2

0

我认为 Application 是一个保留字。尝试重命名 LoanApplication?

于 2015-10-22T02:13:16.907 回答
0

这很简单,我只需要添加class_name: "Transfer"所有内容即可。-__-'

于 2015-10-22T07:46:40.150 回答