我正在尝试遍历名为@items
的数组。我想通过将它添加到类变量并从SLIM调用它我可能能够输出数组。我做错了什么?
require "rubygems"
require "sinatra"
require "slim"
set :port, 80
get "/" do
slim :index
end
get "/history" do
@items = Dir.entries(File.expand_path(File.dirname(__FILE__)) + "/history").to_a
slim :history
end
__END__
@@layout
doctype html
html
head
title Web View
body
div id="main" name="main"
h1 Web View
== yield
@@index
h2 Available Options
a href="/history" id="history_view" name="history_view" History
@@history
h2 History
- unless items.empty?
- for item in items do
a href="#{item}/output.html" item
- else
p NO ITEMS FOUND
答案 0 :(得分:2)
您似乎已尝试在“历史记录”布局中调用items
方法。除此之外,请查看else
子句的缩进级别。尝试更改您的代码:
h2 History
- unless @items.empty?
- for item in @items do
a href="#{item}/output.html" item
- else
p NO ITEMS FOUND