我需要一些幫助來打印我的散列值。在我的「web.rb」文件我有:如何在ERB文件中輸出多維散列?
class Main < Sinatra::Base
j = {}
j['Cordovan Communication'] = {:title => 'UX Lead', :className => 'cordovan', :images => ['http://placehold.it/350x150','http://placehold.it/350x150','http://placehold.it/350x150']}
j['Telia'] = {:title => 'Creative Director', :className => 'telia', :images => ['http://placehold.it/350x150','http://placehold.it/350x150','http://placehold.it/350x150','http://placehold.it/350x150']}
get '/' do
@jobs = j
erb :welcome
end
end
在「welcome.rb」我打印的哈希值,但它不工作:
<% @jobs.each do |job| %>
<div class="row">
<div class="span12">
<h2><%=h job.title %></h2>
</div>
</div>
<% end %>
這裏是我的錯誤信息:
NoMethodError at/undefined method `title' for #<Array:0x10c144da0>
當迭代器不輸出你想要的內容時,嘗試檢查'@ jobs.each.to_a'輸出的內容。 – nicooga 2013-03-11 16:04:07