0
新的紅寶石/鐵軌,請容忍我。Ruby/Rails:使用塊迭代ActiveRecord查詢結果?
我執行了一個查詢並將其存儲在位於我的控制器中的@variable中。在我看來,我要輸出的結果作爲一個列表,像這樣:
控制器:
def new
@content = OrientationContent.where("site_id in (?)", [0, session[:site_id]])
end
查看:
<%= @content.each do |c| %>
<ul>
<li><%= c.content %></li>
</ul>
<% end %>
然而,我的輸出出來像這樣:
Check 1
Check 2
Check 3
Check 4
Check 5
Check 6
[#<OrientationContent id: 17, site_id: 0, content: "Check 1", created_at: "2014-12-26 03:46:25",
updated_at: "2014-12-26 03:46:25">, #<OrientationContent id: 18, site_id: 0, content: "Check
2", created_at: "2014-12-26 03:46:25", updated_at: "2014-12-26 03:46:25">
由於有點長,我故意切斷輸出。但它對所有檢查項目從1到6.
更多的,當我做(1..5)時,每個都做| c |
將輸出數字1到5,並在年底它也將輸出「(1..5)」
我的問題是如何保持輸出的第一部分,而不是下半年(在我的第一個例子,我不希望輸出的記錄在我的第二個例子,我不希望「(1..5)」,以示
總是小事,謝謝奧雅納!我會在11分鐘內接受答案! – AMoghrabi