在 Rails 中将属性从哈希数组打印到 erb?
我是 Ruby on Rails 的新手,有点困惑。我有一个通过助手中的 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>
我什至无法从第一步开始,即解析大批。当我尝试 each 循环的不同变体时,它们只是打印出完整的数组。 有没有一种简单的方法可以做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: