简体   繁体   English

Ruby&Mongoid-未初始化的常量

[英]Ruby & Mongoid - Uninitialized constant

I'm getting "uninitialized constant SwimResult": 我收到“未初始化的常量SwimResult”:

class LegResult
  include Mongoid::Document
  field :secs, type: Float
  embedded_in :entrant
  embeds_one :event, as: :parent
  validates_presence_of :event

  after_initialize do |doc|
    doc.calc_ave
  end


  def calc_ave

  end

  def secs=value  
    self[:secs] = value
    calc_ave

  end
end


class SwimResult < LegResult
  field :pace_100,  as: :pace_100, type: Float

  def calc_ave
  end
end



class BikeResult < LegResult
  field :mph,  as: :mph, type: Float

  def calc_ave
  end
end

I know it can occur when classes are in a separate files, but in my case they're all in one - class LegResult and two subclasses inheriting after it. 我知道当类位于单独的文件中时会发生这种情况,但就我而言,它们全都在一个类中-LegResult类和在其后继承的两个子类。 I'll appreciate any help. 我将不胜感激。

您需要将SwimResult和BikeResult类移至swim_result.rb和bike_result.rb之前,请确保要求输入“ leg_result”,这将确保文件以正确的顺序加载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM