无法在 Slim 逻辑中迭代数组
我正在尝试迭代名为 @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
I am trying to iterate through an array named @items
. I thought by adding it to a class variable and calling it from SLIM I might be able to output the array. What am I doing wrong?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎尝试在“历史记录”布局中调用
items
方法。除此之外,请查看else
子句的缩进级别。尝试更改您的代码:It seems that you've tried to call
items
method in your 'history' layout. Besides this look at indentation level for yourelse
clause. Try to change your code: