本文介绍了页面出现意外的数组输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在列出特定数据库表表的一组数据(为简单起见,仅标识列),如下所示:

I'm listing a set of data (for simplicity sake, just the identity column) of a particular database table table as follows:

<%= @fields.select{|field| field.model=="PreferredOffering"}.each do |field| %>
    <%= field.id %>
    <br/>
<% end %>

您可能是从上面收集到的,我正在使用selecteach的组合来仅循环访问其列model包含字符串PreferredOffering的行.

As you may have gathered from above, I'm using the combination of select and each to iterate ONLY through rows whose column model contains the string PreferredOffering.

我的期望是,我会看到一个很好的有序数字列表,确实如此.我的困惑是我还看到整个@fields数组在数字列表下方的整个页面中咳嗽. (请参见下面的HTML摘录)

My expectation was that I would see a nice ordered list of numbers and indeed I do. My confusion is that I ALSO see the entire @fields array coughed all over the page, below the list of numbers. (See below html excerpt)

106
<br/>

107
<br/>

108
<br/>

109
<br/>

110
<br/>

111
<br/>

112
<br/>
[#&lt;PreferredOfferingField id: 5, field_heading: &quot;Anti-dilution provisions- Typical Weighted Average&quot;, category: &quot;Anti-Dilution&quot;, intra_cat_order: 1, model: &quot;P

我的猜测是我对select做一些有趣的事情,因为我对它的用法并不十分熟悉.

My guess is that I'm doing something funny with select as I'm not really familiar with its usage.

任何有关如何解决此问题的想法将不胜感激;预先感谢.

Any ideas on how to remedy this would be received gratefully; thanks in advance.

推荐答案

<% %> 在内部执行Ruby代码

<%= %> 打印结果

您正在显示数组,然后是它的值,因此您想将<%= %>更改为<% %>.

You are displaying array and then it's values, so you would want to change <%= %> to <% %> .

<%= @fields.select{|field| field.model=="PreferredOffering"}.each do |field| %>

<% @fields.select{|field| field.model=="PreferredOffering"}.each do |field| %>

这篇关于页面出现意外的数组输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 02:26