I'm new to Ruby on rails and am a bit confused. I have an array of hashes that I parsed through json in a helper:
a = [{"desc"=>"testdesc1", "owner"=>{"url"=>"https://www.example1.com"},
{"desc"=>"testdesc2", "owner"=>{"url"=>"https://www.example2.com"}]
and now I want to display it in my .erb like this:
<h3>name (with link to url)<h3>
<div>desc</div>
I cannot even begin with the first step, which is to parse the array. When I try different variations of the each loop they simply print out the full array. Is there a straightforward way to do this?
Try this:
array.each do |entry|
<h3><a href="#{entry["owner"]["url"]}"> entry["name"] </a></h3>
<div>entry["desc"]</div>
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.