0
我在使用紅寶石表時遇到問題。我允許用戶通過前綴或標題來搜索類,以便將它們發送到found_by_prefix或found_by_title頁面,我需要使用find_all_by_prefix(params[:prefix])
。所以當我這樣做的時候,我得到了一個錯誤,所以我研究了它,發現使用<%[email protected](&:prefix).join(', ')%>
會把所有在我的表中找到的課程,但它只是把所有的結果放在一行。我只想知道如何爲4個結果製作4行!使用find_all_by Ruby時出錯ERROR
控制器:
def found_by_prefix
@course = Course.find_all_by_prefix(params[:prefix])
end
查看:
<table border=1>
<tr><th>id</th><th>prefix</th><th>number</th><th>title</th><th>section</th></tr>
<tr>
<td><%[email protected](&:id)%></td>
<td><%[email protected](&:prefix).join(', ')%></td>
<td><%[email protected](&:number).join(', ')%></td>
<td><%[email protected](&:title).join(', ')%></td>
<td><%[email protected](&:section).join(', ')%></td>
</tr>
</table>
閱讀:http://guides.rubyonrails.org/active_record_querying.html – shibly 2012-01-31 01:05:15