代码之家  ›  专栏  ›  技术社区  ›  Anthony

ruby未初始化常量

  •  0
  • Anthony  · 技术社区  · 14 年前

    我经常会遇到这样的错误:

    未初始化的常量GetxmlController::Xmlparse

    require "rexml/document"
    include REXML
    
    Class Xmlparse
      def parsetime
        xmlfile = File.new("colors.xml")
        xmldoc = Document.new(xmlfile)
        root = xmldoc.root
        return root
      end
    end
    

    我的控制器看起来像:

    class GetxmlController < ApplicationController
      def findxml
        @hxml=Xmlparse.new
        @test1=@hxml.parsetime
      end
    end
    

    2 回复  |  直到 4 年前
        1
  •  11
  •   Chuck    14 年前

    在Ruby中不要大写“Class”。

        2
  •  2
  •   sameera207    14 年前

    需要“rexml/document”