sinatra/haml 中未初始化常量 Tilt::CompileSite::Nokogiri 错误

发布于 2024-09-28 13:05:57 字数 576 浏览 0 评论 0原文

我有一个两行脚本,可以在 ruby​​ 中很好地工作。 收到错误

我将其移至 haml 并在 / 处 NameError 未初始化的常量 Tilt::CompileSite::Nokogiri

haml 代码:

      %td
        - @doc = Nokogiri::XML(File.open(file))
        = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }

知道如何让它工作吗?

上使用以下内容

  • 在 Win XP SP3 ruby​​ 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • nokogiri (1.4.3.1 x86-mingw32)
  • sinatra (1.0)
  • Thin (1.2.7 x86-mswin32)

I have a two line script that works nicely in ruby. I moved it to haml and getting the error

NameError at /
uninitialized constant Tilt::CompileSite::Nokogiri

the haml code:

      %td
        - @doc = Nokogiri::XML(File.open(file))
        = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }

any idea how I can make it work?

using below on Win XP SP3

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • nokogiri (1.4.3.1 x86-mingw32)
  • sinatra (1.0)
  • thin (1.2.7 x86-mswin32)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星星的軌跡 2024-10-05 13:05:57

试试这个:

%td
  - @doc = ::Nokogiri::XML(File.open(file))
  = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }

Try this:

%td
  - @doc = ::Nokogiri::XML(File.open(file))
  = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }
夢归不見 2024-10-05 13:05:57

仍然不知道为什么会发生错误,但我通过在 sinatra 文件中定义一个函数并在 haml 文件中调用它来解决它 = get_testsuite(file)

def get_testsuite (file)

  @doc = Nokogiri::XML(File.open(file))
  output = Array.new
  @doc.xpath("//testsuite").each_with_index {|node,index|
    output << "#{index+1}. #{node.attributes["name"].value}<BR>"
  }
  return output
end

still do not know why the error happens but I solved it by have a function defined in sinatra file and calling it in haml file = get_testsuite(file)

def get_testsuite (file)

  @doc = Nokogiri::XML(File.open(file))
  output = Array.new
  @doc.xpath("//testsuite").each_with_index {|node,index|
    output << "#{index+1}. #{node.attributes["name"].value}<BR>"
  }
  return output
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文