我有一个奇怪的情况,我无法弄清楚。我有一个pages
模型和videos
模型。视频模型很简单,是页面中的嵌套模型。一切正常,但由于某些原因,当我循环浏览视频嵌套属性时,它会将对象数组打印到视图中。我在下面包含了我的循环和截图。
页/ show.html.erb
...
<div class="row">
<div class="col-md-12">
<%= @page.videos.each do |v| %>
<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= v.youtube %>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
<% end %>
</div>
</div>
...
你只需要在循环中删除'='这就是使数组打印正确的代码片段将是这样的
<div class="row">
<div class="col-md-12">
<% @page.videos.each do |v| %>
<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= v.youtube %>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
<% end %>
</div>
</div>