html - Ruby cgi 表错误

标签 html ruby cgi

我正在编写 cgi ruby​​ 并收到以下错误:

ruby5_ac1.cgi:74: syntax error, unexpected '\n', expecting tASSOC

我认为 cgi.table 末尾的 curl 有错误,但所有 curl 都是匹配的所以我不知道这有什么问题 .

代码:

#!/usr/local/bin/ruby
require 'uri'
require 'cgi'
cgi = CGI.new("html4")
cgi.out {
cgi.html {
  cgi.head { cgi.title{"Search Job Bank"} } + "\n" + 
  cgi.body { "\n" + 
      cgi.h1 { "Jobs from VA databank" } +
      cgi.table("border"=>"1")
  {
      cgi.tr {
     cgi.td {"Artist"} + 
     cgi.td {"Album"} } +
      cgi.tr {
     cgi.td {"Davis, Miles"} +
         cgi.td {"Kind of Blue"} } 
      }
  }
}
}

最佳答案

写成如下:

#!/usr/local/bin/ruby
require 'uri'
require 'cgi'
cgi = CGI.new("html4")
cgi.out {
cgi.html {
  cgi.head { cgi.title{"Search Job Bank"} } + "\n" + 
  cgi.body { "\n" + 
      cgi.h1 { "Jobs from VA databank" } +
      cgi.table("border"=>"1") { # <~~ see this is a fix.
      # you placed this `{` below of `cgi.table("border"=>"1")` 
      # so it seemed like a Hash. But it should be a block's open brace.
      cgi.tr {
     cgi.td {"Artist"} + 
     cgi.td {"Album"} } +
      cgi.tr {
     cgi.td {"Davis, Miles"} +
         cgi.td {"Kind of Blue"} } 
      }
  }
}
}

关于html - Ruby cgi 表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22280551/

相关文章:

ruby - 为什么要使用字符串键来对符号进行哈希

ruby - 获取与另一个偏移的字符

python - CGI脚本编写安全

web-services - 如何在 Ubuntu 中部署 gSOAP Web 服务?

html - 即使在折叠时也将无序列表设置为内联 *Bootstrap*

php - 网站链接在 google chrome 上不起作用,但在 firefox 上工作正常

菜单旁边的 HTML 文本显示

javascript - CheckBoxFor 生成错误的 HTML

ruby-on-rails - 'after_filter' 如何/何时工作/运行?

c++ - 使用 C++ CGI 创建环境变量