[英]Printing properties from an array of hashes to an erb in Rails?
我是Ruby的新手,有些困惑。 我在助手中通過json解析了一系列哈希:
a = [{"desc"=>"testdesc1", "owner"=>{"url"=>"https://www.example1.com"},
{"desc"=>"testdesc2", "owner"=>{"url"=>"https://www.example2.com"}]
現在我想在我的.erb中顯示如下:
<h3>name (with link to url)<h3>
<div>desc</div>
我什至不能從第一步開始,即解析數組。 當我嘗試每個循環的不同變體時,它們只是打印出完整的數組。 有沒有簡單的方法可以做到這一點?
嘗試這個:
array.each do |entry|
<h3><a href="#{entry["owner"]["url"]}"> entry["name"] </a></h3>
<div>entry["desc"]</div>
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.